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

Repopulating a web form with Code Igniter - 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.

  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



To be frank, creating the view file responsible for displaying all the errors that might occur when validating the sample web form, and for repopulating its fields when applicable, is a straightforward process that you’ll grasp very quickly.

However, to clarify how this view is going to work, please examine its corresponding signature, which is shown below:

<!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">


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

<title>Entering user data</title>



<h1>Entering user data</h1>

<?php echo $this->validation->error_string;?>

<?php echo form_open('validator');?>

<p>First Name <input type="text" name="firstname" value="<?php echo $this->validation->firstname;?>" size="50" /></p>

<p>Last Name <input type="text" name="lastname" value="<?php echo $this->validation->lastname;?>" size="50" /></p>

<p>Email <input type="text" name="email" value="<?php echo $this->validation->email;?>" size="50" /></p>

<p><input type="submit" value="Send Data" /></p>




Definitely, that wasn’t rocket science, was it? As shown before, the above view file is responsible for displaying a simple contact form, which not surprisingly is composed of three text boxes, which come in handy for entering typical data, such as the user’s first and last names, and an email address as well.

Nevertheless, if you have a closer look at the view file in question, then you’ll see that on top of it, the Code Igniter validation class is used to display all of the  errors that might arise when validating the web form. Other than that, there are a few additional PHP statements interspersed with the structural markup, which are used to repopulate the form’s fields and to generate dynamically the URL for its “action” attribute.

Now you have learned how to build a simple view file that not only will be capable of displaying on screen all of the error messages that occurred when validating the sample HTML form, but will refill its fields with the data entered previously by a user.

Therefore, save this file to the Code Igniter /system/application/views/folder as “webform_view.php” and once you’ve done this, please jump forward and read the following section. In that part, I’ll explain how to build the remaining view file, which will be responsible for showing a confirmation message, after the web form has been submitted successfully.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: