PHP 5 Form Validation
This and the following sections tell the best way to utilize PHP to approve structure data.
$_SERVER is a cluster that incorporates data, for example, headers, ways, and content areas. The sections in this cluster are made by the web server.
PHP Form Validation
The HTML structure we will work at in these sections, contains different information fields: required and discretionary content fields, radio catches, and a submit button:
The approval rules for the structure above are as follows:
|Name||Required. + Must just contain letters and whitespace|
|Required. + Must contain a legitimate email address (with @ and .)|
|Website||Optional. In the event that present, it must contain a substantial URL|
|Comment||Optional. Multi-line input field (textarea)|
|Gender||Required. Must choose one|
First we will take a gander at the plain HTML code for the form:
The name, email, and site fields are content info components, and the remark field is a textarea. The HTML code looks like this:
Email: <input type="text" name="email">
Website: <input type="text" name="website">
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
The sexual orientation fields are radio catches and the HTML code looks like this:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
The Form Element
The HTML code of the structure looks like this:
When the structure is presented, the structure information is sent with method="post".
So, the $_SERVER["PHP_SELF"] sends the submitted structure information to the page itself, rather than hopping to an alternate page. Along these lines, the client will get blunder messages on indistinguishable page from the form.
Big Note on PHP Form Security
The $_SERVER["PHP_SELF"] variable can be utilized by hackers!
If PHP_SELF is utilized in your page then a client can enter a cut (/) and afterward some Cross Site Scripting (XSS) directions to execute.