Show submitted form response on the same page. (No Reload)

前端 未结 4 2073
野的像风
野的像风 2020-12-14 13:38

How would I go about showing the response from a submitted contact form (on the same page underneath the form) rather than sending the user to a new page after the submissio

4条回答
  •  渐次进展
    2020-12-14 14:04

    This is a working example using the suggested example from the JQuery site and pajaja's answer.

    Solution:

    Place this in the of your webpage.

    OR

    Download JQuery and include it the same way.

    Form:

    Your contact form remains un-changed.

    Returned Data:

    Add your response element where you want in the body.

    Javascript:

    Now place (preferably just before ) the javascript code:

    
    

    Action Script:

    Your contact (PHP) file remains the same but change $_GET to $_POST:

    Thank you for your comment";
        }
        else
        {
            echo "

    Sorry, there has been an error

    "; } ?>

    Result:

    This should now send the data from the form on submit and then display the returned data in the #contactResponse element. The button will also set the text to "Sent, Thank you" while also disabling the button.

提交回复
热议问题