|
I think you have missunderstood the way php works. Unlike JavaScript, which is run in the browser and can do things without reloading the page, php is a server side language (runs on the server, not in the browser). So for any php code to be executed you have to reload the page, go to a new page, submit a form etc. Anything that will send a new request to the server so that a page is loaded.
This means, you can not have php validate your form before it is sent. Instead you must send the form, retrieve the submited data and validate it. If the data is ok then do what you intentionally wanted to do with it (send as a mail, store in a file, print some message etc.). If the data does not validate you would normally give an error message, display the form again and ask the user to fill it in properly.
And just to make it clear, evan though I wrote "So for any php code to be executed you have to reload the page", this isn't just some downside of php in perticular. This is the way all serverside languages work, hence the name serverside.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
|