PHP Generator for MySQL online Help
Prev | Return to chapter overview | Next |
Data Validation
Data validation is intended to provide certain guarantees for accuracy and consistency for any of various kinds of user input. PHP Generator for MySQL allows you to check for correctness of input data on the client side and on the server side as well.
Client-side data validation
This type of data validation refers to validation performed on the client side. That is, it's performed on the client's, also known as the user's, computer. This type of validation checks the input information before it gets to the server. It has following advantages:
• | Reducing the amount of traffic to and from your web server since the data doesn't have to travel to the server before it gets checked (server-side data validation). If an error is found in the data in the server-side validation, the error must travel back to the user, who then corrects the problem and resubmits the data. This back-and-forth traveling can eat up precious bandwidth. |
• | Saving processing time on the server by ensuring that data is clean and clear before it gets to your database. |
• | Giving immediate feedback to your users since the processing is performed in their browsers. The user doesn't have to wait for the data to travel to the server to be checked and a response to be sent. They know immediately whether they need to tweak the information they have entered. |
PHP Generator for MySQL allows you to implement the client-side data validation on two levels: when a user leaves a certain control and when a user submits a form.
To enable validation of data entered in a control, specify the appropriate Client validator.
Range |
The generated script validates if number is between the largest and smallest values. |
Length range |
The script validates if the length of text is between the min length and the max length. |
The script makes the element require a valid email. |
|
Credit card |
The script makes the element require a credit card number. |
Number |
The script makes the element require a decimal number. |
URL |
The script makes the element require a valid URL. |
Digits |
The script makes the element require digits only. |
Regular expression |
You can also specify your regular expression for data validation. Such expression is a pattern and every character entered in a form field is matched against that pattern – the form can only be submitted if the pattern and the user-input matches. |
To implement data validation on submitting a form, use the OnInsertFormValidate and OnEditFormValidate client side events. It may be helpful to check the compatibility of input data. When a user clicks the Save button, Javascript ensures that the data conforms to specifications before moving on the server.
Server-side data validation
This type of data validation consists of validating user input on the server.
This type of data validation means using PHP to verify that good values have been sent to the script. Using server-side validation has pretty much the exact opposite pros and cons of client-side development: it is more secure, works seamlessly with all browsers, and allows to use session variables, but it does so at the cost of slightly higher server load and slower feedback for users.
Prev | Return to chapter overview | Next |