Results 1 to 5 of 5

Thread: Form validation & Thank you page

  1. #1
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default Form validation & Thank you page

    Ok, I've made a pretty basic contact form that gets emailed to me... However, I can't figure out how to validate it using PHP instead of javascript. I also want to somehow send the user to a "thank you page" after submission. The thank you page will just be a quick "Thanks for submitting your request" or something like that.

    Here's a working version:
    http://eight7teen.com/DD/formtest/linkad.html


    Here's the php script:
    PHP Code:
    <?php
      $first 
    $_POST['fName'];
      
    $last $_POST['lName'];
      
    $email $_POST['eMail'];
      
    $url $_POST['rURL'];
      
    $length $_POST['howLong'];
      
    $adtype $_POST['adSelect'];
      
    $desc $_POST['bDesc'];

      
    $subject "New Ad Request";


      
    $message "You've recieved an Ad Request:\n\n\nFirst name: " $first "\nLast name: " $last "\nEmail: " $email "\nRelated URL: " $url "\nWhich Ad: " $adtype "\nHow Long: " $length "\n\nDescription of Site:\n <em>" $desc "</em>";


      
    $myemail "josh@eight7teen.com";

      
    $headers 'From: adRequest@eight7teen.com' "\r\n" .
        
    'Reply-To: josh@eight7teen.com' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

      
    mail($myemail$subject$message$headers);
    ?>
    Last edited by TheJoshMan; 11-14-2008 at 06:12 PM.
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    PHP Code:
    $first $_POST['fName'];
      
    $last $_POST['lName'];
      
    $email $_POST['eMail'];
      
    $url $_POST['rURL'];
      
    $length $_POST['howLong'];
      
    $adtype $_POST['adSelect'];
      
    $desc $_POST['bDesc'];
      
    $flag=true;
      
    $mandate=array($first$last$email); // Mandatory fields
      
      
    if(empty($first))
      echo 
    'I need to know your first name';
      elseif(empty(
    $last))
      echo 
    'I need to know your last name';
      elseif (empty(
    $email))
      echo 
    'How about your email?';
      elseif(!
    preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/"$email))
      echo 
    'Please check your email. It\'s invalid.';
      else if(!isset(
    $url))
      echo 
    'Please let me know the url';
      
        
    else
    {
      
    $message "You've recieved an Ad Request:\n\n\nFirst name: " $first "\nLast name: " $last "\nEmail: " $email "\nRelated URL: " $url "\nWhich Ad: " $adtype "\nHow Long: " $length "\n\nDescription of Site:\n <em>" $desc "</em>";


      
    $myemail "josh@eight7teen.com";

      
    $headers 'From: adRequest@eight7teen.com' "\r\n" .
        
    'Reply-To: josh@eight7teen.com' "\r\n" .
        
    'X-Mailer: PHP/' phpversion();

        echo 
    '<h1>Thank You! Email sent</h1>';
      
    mail($myemail$subject$message$headers);

    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. The Following User Says Thank You to rangana For This Useful Post:

    TheJoshMan (11-14-2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    that looks simple enough, but it gives me a parsing error.

    here's the link: http://eight7teen.com/DD/formtest/linkad.html

    Parse error: syntax error, unexpected $end in /mnt/w0503/d26/s30/b02d3b61/www/eight7teen.com/DD/formtest/sendit.php on line 37
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

  5. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    It's working fine at my end when tested I guess you'll receive an email at your end.

    Please ensure that the brackets have a matching closing for opening and vice versa.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  6. The Following User Says Thank You to rangana For This Useful Post:

    TheJoshMan (11-14-2008)

  7. #5
    Join Date
    Jan 2006
    Location
    Ft. Smith, AR
    Posts
    795
    Thanks
    57
    Thanked 129 Times in 116 Posts

    Default

    that's what it was, I guess I missed a curly bracket on the last else statement.

    Thanks a million man!
    --------------------------------------------------
    Reviews, Interviews, Tutorials, and STUFF
    --------------------------------------------------
    Home of the SexyBookmarks WordPress plugin

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
  •