PHP
  Home arrow PHP arrow Page 3 - Validating Web Forms with the Code Ign...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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: 5 stars5 stars5 stars5 stars5 stars / 3
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


       · As usual with many other PHP frameworks, Code Igniter comes equipped with a useful...
       · Its spelled CodeIgniter not Code Igniter. :))
       · Thanks for catching that. The correct name is CodeIgniter.Regards.
       · Thanks for the articles It is a great help.If the form is submitted with one...
       · Thanks for the comment on my CI article. Regarding your question, you should use the...
     

       

    PHP ARTICLES

    - Using Aliases and the Autoload Function with...
    - Authentication Scripts for a User Management...
    - Utilizing the Use Keyword for Namespaces in ...
    - Building a User Management Application
    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Sub Classing Exceptions in PHP 5
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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