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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User data submitted successfully!</title>
<h1>User data submitted successfully!</h1>
<p><?php echo anchor('validator','Go and submit the form again');?></p>
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:
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.
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!
blog comments powered by Disqus