treehouse : what would you like to learn today?
Web Design Web Development iOS Development

PHP + jQuery Contact Form - Recommendation

  • Hello everyone,

    I am building a contact form as well as a registration form to be included in a Wordpress template. So far the form is styled and the jQuery validation is working correctly. What I would like the form to do when it is submitted is do the back end validation, email the info to a set email address and then replace the form with a success message.

    Can anyone recommend a good tutorial? I have googled it but I seem to be swimming in a sea of contact forms.


    Thanks.
  • Thanks for the link.

    I used the script and it passes on the info fine but I am wondering how I can go about displaying the success or failure message on the original contact page rather than having a new page loaded.

    User fills out info -> user clicks submit -> info is validated -> form disappears or fades out and is replaced by the success or failure message
  • Find this at the bottom:

    if(mail($to, $subject, $message, $headers))
    {
    $result = \"<b>Thank you</b>.<br />I will get back to you very soon.<br />\";
    }
    else
    {
    $result = \"Sorry: An error occured, please try again later.\";
    }
    }


    And replace it with something like this:

    $result = \"../contact-success.php\";
    $errorpage = \"../contact-error.php\";

    if(mail($to, $subject, $message, $headers))
    {
    header(\"Location: \" . $result);
    }
    else
    {
    header(\"Location: \" . $errorpage);
    }
    }