Home arrow PHP arrow Page 4 - Performing Strict Validation with the Code Igniter PHP Framework

Completing the form validation application - PHP

Welcome to the fifth article in our nine-part series on the Code Igniter framework. In the last article you learned a very simple way to use the framework to check information supplied by users through an HTML form. The type of checking done was very simple, however, and user-supplied data must be checked and validated pretty strictly for many purposes. This article will show you how to improve the previous application's validation mechanism.

TABLE OF CONTENTS:
  1. Performing Strict Validation with the Code Igniter PHP Framework
  2. Performing strict validation on user-provided data with Code Igniter
  3. Repopulating a web form with Code Igniter
  4. Completing the form validation application
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
September 10, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In the prior section, I demonstrated how simple it is to check data entered into a sample online form by means of the validation class that comes with Code Igniter. As you saw earlier, it’s perfectly possible to repopulate its fields, too, by adding only a few lines of PHP code.

Nonetheless, to finish developing this HTML form validation application, it’s necessary to generate yet another view file. This file will be tasked with displaying on the browser a simple confirmation message once the pertinent form has been submitted successfully.

So, with this in mind, below I included the definition of this brand new file:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>User data submitted successfully!</title>

</head>

<body>

<h1>User data submitted successfully!</h1>

<p><?php echo anchor('validator','Go and submit the form again');?></p>

</form>

</body>

</html>


Did you ever think that creating a confirmation view like the one shown above was pretty difficult? Well, fortunately you were wrong! As you can see, the previous view simply will print on screen a typical message indicating the HTML form has been submitted successfully, as you’ve done probably hundreds of times before.

In addition, it’s worthwhile to notice how the “url” helper function provided by Code Igniter is utilized in this specific case, to include a link that points back to the controller. Of course, this could have been done manually, but I left this task to be accomplished by this helper.

Now that you have grasped how the previous view file does its business, save it to the Code Igniter /system/application/views/ folder as “success_view.php” and finally type the following URL into your browser’s address field to test this sample web application:


http://localhost/codeigniter/index.php/validator/


Here you have it. At this moment, you’re armed with the required background to start developing your own data checking applications with Code Igniter. Try setting other rules for the validation class, and see what happens in each case.

Final thoughts

In this fifth chapter of the series, I explained how to use the validation class that comes bundled with Code Igniter to validate more strictly the data entered into a sample web form. As you saw before, thanks to the functionality provided by this class, the whole process was fairly simple to follow.

In the next part, I’ll show you how to work with Code Igniter’s active record class. In this way you can learn how to select, insert, update and delete database rows without having to get your hands dirty writing SQL statements.

Don’t miss the next article!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: