Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 5 years ago.
I'm working on a form for my website. The markup for the form tag looks like:
<form method="post" action="contactengine.php">
The form sends an email to me using action="contactengine.php" with the form information when a user submits it. Because of the page layout I have, however, I can't have the page reload when a user submits the form. How can I work around this issue?
Are you able to use javascript + jquery? Posting asynchronously is fairly simple with jquery.
$('#formid').submit(function({ //listens for form submission
$(this).preventDefault(); //stops the submission
$.post('actionPage.php', $(this).serialize, function(response){
//posts the data to actionpage.php, with the form data, and then runs a function handling the response.
});
}));
Have the server respond with a 204 No Content
response (spec).
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view
Such:
<?php
http_response_code(204);
exit();