SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict Kysmiley's Avatar
    Join Date
    Dec 2004
    Location
    Isonville KY
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP becomes it's own page

    At what point do you make a specific page for you PHP script instead of having it as part of your HTML page. I am doing a contact page. I want to place validation, spam control and a way to forward users to a thank-you page after they fill out the form. Just as a guild line when do others make a page specific for PHP and have the information from a form passed on to the PHP page. I hope this question was wordeed correctly?
    Pat

  2. #2
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually post the form on the same page so that if some error occurs i can prefill the form fields and display the error and if the process completes successfully i redirect user to to thankyou page so that post fields is cleared.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Juuh View Post
    I usually post the form on the same page so that if some error occurs i can prefill the form fields and display the error and if the process completes successfully i redirect user to to thankyou page so that post fields is cleared.
    Ditto.

  4. #4
    SitePoint Addict Kysmiley's Avatar
    Join Date
    Dec 2004
    Location
    Isonville KY
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is where I am having a hard time. I have a php post to self in the form, yet I want to echo the form if the email field is not filled in or done incorrect. I keep getting an error message. Here is my complete code.

    <?php include("inc/header.inc.php"); ?>
    <!--start content-->
    <div id="content">
    <div class="contactform">

    <?php

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    function spamcheck($field)
    {
    //filter_var() sanitizes the e-mail
    //address using FILTER_SANITIZE_EMAIL
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);

    //filter_var() validates the e-mail
    //address using FILTER_VALIDATE_EMAIL
    if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
    else
    {
    return FALSE;
    }
    }

    if (isset($_post['email']))
    {//if "email" is filled out, proceed

    //check if the email address is invalid
    $mailcheck = spamcheck($_post['email']);
    if ($mailcheck==FALSE)
    {
    echo "Invalid input";

    }
    else
    {//send email


    //create short variable names

    $fname = $_POST['fname'];

    $lname = $_POST['lname'];

    $email = $_POST['email'];

    $comments = $_POST['comments'];



    $toaddress = 'me@bluegrassmountain.com';

    $subject = 'Comments from Our Web-site';

    $mailcontent = 'Customer name: '.$fname.' '.$lname."\n".'Customer Email: '.$email."\n".'Customer Comments: '.$comments."\n";

    $fromaddress = 'From: '.$email;

    mail ($toaddress, $subject, $mailcontent, $fromaddress);


    }
    }

    else

    {//if "email" is not filled out, display the form
    echo '<center><h2>Please use our contact form to ask us questions or give comments...</h2></center>

    <form name="contact_us" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

    <div>

    <label for="fname">First Name</label>

    <input size="40" type="text" name="fname" id="fname" />

    </div>

    <br />

    <div>

    <label for="lname">Last Name</label>

    <input size="40" type="text" name="lname" id="lname" />

    </div>

    <br />

    <div>

    <label for="email">Email</label>

    <input size="40" type="text" name="email" id="email" />

    </div>

    <div>

    <label for="comments">Please tell us your comments or questions</label><br />

    <textarea cols="40" name="comments" rows="10">

    </textarea><br />

    <input type="submit" value="Tell us" />

    </div>

    </form>



    </div>
    <p>some text here
    </p><br/><br/>'

    }

    }

    ?>
    I dont have the part about sending the user to the thank-you page on here yet. The code that was given to me does not work it conflicts with my header include.
    Pat


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •