Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Automatic php form validation with HTML5 (required)
Friday - Dec 18th 2015 - by - (0 comments)

I just realized that I love HTML5. I'm programming a PHP form and I remember that 10 years ago I had to verify and sanitize all form input types if they were set/filled in by checking the $_POST data.

Now with HTML5 the job got a lot easier (and faster!). Instead of manually analyzing the submitted data after the user hit post/submit, the browser can now do the job on his own. The magic is done by the "required" parameter in a form element.

For instance:

    <input type="radio" name="iEnvironment" value="prod" required>PROD
    <input type="radio" name="iEnvironment" value="qual" required>QUAL
    <input type="radio" name="iEnvironment" value="stage" required>STAGE
    <input type="radio" name="iEnvironment" value="test" required>TEST

When the user submits the form, the browser verifies if the required fields are selected. In this case the radio button with name "iEnvironment" needs to be set. So at least one of the four options must be selected. If the user doesn't, here's what the browser says:

HTML5 form validation with required parameter

It's been a long time since I last programmed a web form in PHP and this new feature just hit me now. Thanks HTML5! 


Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6938 Days
until Death of Computers