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

前端 未结 4 2060
野的像风
野的像风 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 13:44

    You will need to use ajax for that. The simplest solution is to get jQuery javascript library an use it's .post function for which you can find documentation and examples here. In your case it will look something like this:

    
    
    

    Also your PHP code is wrong:

    $name =$_GET['name'];
    $email =$_GET['name'];
    $message =$_GET['name']
    

    You are getting $_GET['name'] for all 3 variables.

    edit: I added a complete example but it is not tested it's just so you can have an idea how to do what you want. Also since this is using HTTP POST request, you will need to edit your PHP so it gets values $_POST array, not $_GET. Also you will need to add a

    where you want to display the response.

提交回复
热议问题