I am writing a contact form using jQuery AJAX POST and PHP. The form works well and sends the email. What I want to know is how to get the return values for error and success on the same page where the contact form is rather than having the message go to another page. I created a DIV called statusBox, and I would like all the messages printed there. Below is the fragment from the jQuery side. What do I need to do on the PHP side to get the values back?

var data_string = $('form#contactform').serialize();

        $.ajax({
            type:       "POST",
            url:        "slidinglabelsFormMail.php",
            data:       data_string,
            success:    function(response) {
                $('#statusBox').html(response);
                $('#statusBox').html('<div id="success"></div>');
                $('#statusBox').html('<h3>Success</h3><p>Your email has been sent.</p>');

            },//end success function
            error: function(response){
                $('#statusBox').html(response);
            }
        }) //end ajax call
        return false;

Recommended Answers

All 2 Replies

Can't you just echo out the success or email failure from php? which would print out in your div!!?

Or you can build up a JSON with appropriate structure of capturing success or failure message

Can't you just echo out the success or email failure from php? which would print out in your div!!?

Or you can build up a JSON with appropriate structure of capturing success or failure message

I just got back to this and figured out my error just before you wrote this note.
Thanks!
WBR

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.