Wmlscript example validating form data

Most often, the purpose of data validation is to ensure correct user input.

Validation can be defined by many different methods, and deployed in many different ways.

In our php validation snippet : if ( isset ( $_POST['submit'] ) ) { // Checking null values in message.

$name = $_POST["name"]; // Sender Name $email = $_POST["email"]; // Sender's email ID $message = $_POST["message"]; // Sender's Message So, now our form’s data is being repopulated and user irritates a lot lesser.

By sanitizing the data, you take the responsibility of hunting for the mistake off of the user.

So, now we can now sanitize and validate user’s email address.

IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

So, we need to always filter and validate the user entered before storing it in application’s database.

Here I am giving a simple example for form validation using Javascript.

It is not good practice to validate your data in your controller, this should be handled in your Model. Copyright (c) 2012 is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

This class follows Zend Framework naming conventions for easy drop-in as a substitute to Zend_Validation.

If you opt out of using the bulky Zend_Form on your projects, you might choose to use this for quick and painless form validation.

Wmlscript example validating form data