Grow your CSS skills. Land your dream job.

jquery issues

  • # July 21, 2012 at 4:42 pm

    I have been going crazy for two hours trying to get this to work. I have a form, it works fine. After I submit the form, I want to display a success message and hide the form. Right now, after pushing the submit button, the form goes away, the success message displays for the blink of an eye and then the contact page shows normally. That is all fine, I just need the success message to stay up a bit longer.

     < ?php
    if (isset($_POST)) {

    $contactSubject = "";
    $from = "";
    $sendEmail = "";

    $contactName = strip_tags($_POST);
    $subject = strip_tags($_POST);
    $email = $_POST;
    $messages = strip_tags($_POST);
    //check to see if the variables are empty, if they are, just exit
    $validation = true;

    if (empty($contactName) || empty($email) || empty($messages)) {
    $validation = false;
    } else {
    $validation = true;
    }

    if($validation == true){
    $contact = "Contact Name: $contactName n";
    $contact .= "Email: $email n";
    $contact .= "Subject: $subject n";
    $contact .= "Message: $messages n";

    $subject = $contactSubject;
    $headers = 'From: ' . $from . "rn" .
    'Reply-To: ' . $sendEmail . "rn" .
    'X-Mailer: PHP/' . phpversion();


    $recipient = $sendEmail;

    mail($recipient, $subject, $contact, $headers);
    }

    }
    ?>



    • * Denotes Required Field






    • Proper format "name@something.com"















    Your message has been sent


    The jqyery to run the success message is at the bottom of the code

    # July 21, 2012 at 8:00 pm

    Here, try this: http://jsfiddle.net/savver/KCpuR/

    You might wanna check your message before displaying the success message.

    # July 21, 2012 at 8:31 pm

    It didn’t work. What is wrong with the success message?

    # July 21, 2012 at 10:03 pm

    Using jQuery to display a success message is a bad design as how does your client side code know if the email was sent successfully?

    What you need to be doing is using your PHP script to validate the data and check if the email got sent successfully and display a message based on the result.

    # July 21, 2012 at 10:24 pm

    I am using the php to check that it got sent. then I am putting in some jquery to display the success message. I disagree with you that it is bad design as php works very well with html and javascript mixed. Also this is pretty much an accepted practice.

    # July 21, 2012 at 10:24 pm

    I solved it this way


    $(document).ready(function(){
    $('#contact_form').html("
    ");
    $('#success-message').html("

    Contact Form Submitted!

    ")
    .append("

    We will be in touch soon.

    ")
    .hide()
    .fadeIn(10, function() {
    $('#message').append("");
    });
    });
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".