PHP
  Home arrow PHP arrow Page 3 - Validating Web Forms with the Code Igniter PHP Framework
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Validating Web Forms with the Code Igniter PHP Framework
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 10
    2008-09-03


    Table of Contents:
  • Validating Web Forms with the Code Igniter PHP Framework
  • Validating user-supplied data using the MVC pattern
  • Displaying error messages when validating an online form
  • Building a confirmation view file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Validating Web Forms with the Code Igniter PHP Framework - Displaying error messages when validating an online form
    ( Page 3 of 4 )

    In the previous section, you learned how to use a controller class to determine what course of action to take, either when the form in question has been submitted correctly, or when it fails to pass the validation process.

    Now I’m going to show you how to create the view file that displays the pertinent online form, and incidentally, it also shows an error message as a result of the data checking process.

    That being explained, please examine the code below to see how this error view file looks. 

    <!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>Entering user data</title>

    <head>

    <body>

    <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="" size="50" /></p>

    <p>Last Name <input type="text" name="lastname" value="" size="50" /></p>

    <p>Email <input type="text" name="email" value="" size="50" /></p>

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

    </form>

    </body>

    </html>

    As shown above, the previous view file is quite simple to follow. As you can see, it’s comprised of a basic online form that contains three text boxes for collecting the user’s first and last names, and the corresponding email address.

    However, you should notice two important things regarding the way that the above contact form is created. First, a PHP statement has been included at the beginning of it. As you may guess, this is the error message that will be  generated by the Code Igniter validation class when the web form fails to pass the validation process.

    Finally, the view file uses the form helper function loaded previously by the controller to create a <form> opening tag that points exactly to the controller’s location. Naturally, it’s possible to build this tag manually, but using the helper makes sure that the correct URL will always be assigned to the “action” attribute of the online form.

    So far. So good. At this stage, I taught you how to build a simple view file for showing a basic error message when validating a specific web form. In addition, the view will redisplay the form in question if any of its fields has been left empty, so users can repopulate the offending fields with the correct data and resubmit it.

    So, now that you hopefully learned how the previous view file does its thing, save it to the Code Igniter /system/application/views/ folder, and move on to see how to create the view that displays a primitive successful web page when the pertinent web form is submitted correctly.

    To learn the full details for how this brand new view file will be built, please jump ahead to read the next section. 



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT