Wednesday, May 28, 2014

Day 13: PHP Forms and Validations

Today at the Dojo we really kicked things up a notch learning how to use superglobals to validate form inputs and protect hackers from malicious attacks. I have previous experience with rails but I never really understood how it validated the data. All I really did was put validates: presence: true, etc. in the model and all the validation really takes care of itself. Through PHP, I'm having to create a file commonly called process.php that checks all the form inputs to see if they meet criteria.




Our first assignment was to create a simple site (top pic) that consists of a input field that validates the data. If the data was not valid, the page would redirect to the original page and display an error message above the form (middle pic). If the input values were valid, then it would redirect to a success page. Although it was a very simple app, it's just the first stepping stone to more sophisticated applications.

Here's an example of my PHP code that validates the data.


No comments:

Post a Comment