In normal english:
Code:
Code:
//user presses the submit button
if ($agentname has error)
stay on page and display errors
else
submit automatically to next page
__________________
It's important to get a firm grasp on where things are happening. There are two places code can run in this scenario: in the browser (javascript) and on the server (php).
The server runs php script to generate html which it sends to the browser, usually along with some css and javascript. The browser runs javascript which is able to manipulate the html and do other things, including POSTing data back to the server (where it can be processed by php to generate new html, etc.)
So, in your scenario you run the php on the server to generate html including a form, which is sent back to the browser and displayed to the user. The user puts some stuff in the form and clicks submit. What happens then?
In the default scenario the browser will bundle up the data and ship it back in a POST to whatever url the form specified. This php code:
Code:
<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>
... runs on the server when the form is generated and all it does is point the action of the form back at the same script. It's pretty much boiler plate. So in your case the same script that originally generated the form when a GET request was made, will receive a POST when that form is submitted. This is a pretty common round-trip scenario. It is also why you have:
Code:
if ($_SERVER["REQUEST_METHOD"] == "POST")
... which is there so the script can detect when it is receiving POSTed data, as opposed to receiving a GET request for the initial form.
In this scenario nothing in the way of validation is happening on the browser side. The php script will receive the POSTed data and will then check that data to see if it is complete and compliant. If it is then it will do whatever processing is needed, and either return a new view or redirect the user to a new page.
If the data is not complete and compliant the script will usually regenerate the form markup, repeating the valid data, removing the invalid data, and adding some messaging to the user about what was wrong. This is "server-side" validation and is the simplest round-trip validation scenario for form posts. It's a little old school but it works fine for simple sites.
The next evolutionary step forward is to intercept the form post on the client side and validate the data in javascript. There are a lot of ways to do this, but most people these days will just use a framework like jquery.
Whether you keep your behavior server-side, or want to do client-side validation with javascript, you're going to have to write the code to actually check the data. On the server that will be in php, while on the browser it will be javascript and possibly some framework like jquery.