I am using a simple php form I found here http://www.1stwebdesigner.com/tutorials/custom-php-contact-forms/comment-page-2/#comments
But I am having few issues with it. When clicking the submit button I want to be able to stay on my website instead of being redirected on mail.php and just print/echo the sent message on my website instead.
Also I want to make the fields have requirements, like not being empty which I know how to do in php but I must first solve the redirect issue.
What you need is $.ajax from jQuery. This will send a POST request without reloading the page.
Lets say your button is called
myButtonthen for theonClick()event you would call the functionIn your
some.phpyou would then just use$_POST['name']and$_POST['location']to retrieve the information.Edit
Suppose you had an input field. You can retrieve information from such a field via jQuery as well. You can just then send the information from the input field via ajax to you php script
where
yourInputFieldis the ID of the input field. With this you can get this information to the script. If you have multiple elements in a form you might want to look at the function serialize(). Does the same thing in principle, just compresses all the information into a JSON string.