Part of the EllisLab Network
x
 
Create New Page
 View Previous Changes    ( Last updated by George Petsagourakis )

Form Library

Category:Library | Category:Library -> Community | Category:Library -> Forms

The Form library is a complete replacement for the Form helper. It reads an XML document and converts it to an array (via the Xml Library).

Updates

2006-12-08:
* New version, some API changes (options in dropdowns are reversed from previous order!)
* Entire library has been cleaned up and optimized a bit
* Now integrates with the Uploader library to allow the creation of upload forms

2006-11-06:
* <required> is no longer needed, validation rules are used to find required fields
* Changed several bits, parse by fieldsets
* Changed the format of form templates

2006-11-04:
* Made validate() set the form values, no need to set them manually
* Tweaked the valid types and attributes

Features

- Built in validation using CI Validation
- 1 call data retrieval
- XHTML 1.0 output code
- written for PHP5 (not PHP4 compatible)

Usage

$this->load->library('form');
$this->form->load('login'); // Relative to APPPATH/data/forms/, ".xml" appended
if ($data $this->form->post_data()) {
  print_r
($data);
}
else {
  
print $this->form->build();

Library Code

Sample Form:

<?xml version="1.0" encoding="UTF-8" ?>
<form action="user/login" name="user_login">
  <
fieldset name="User Login">
    <
username rules="trim|required|min_length[4]|max_length[32]|xss_clean">
      <
type>text</type>
      <
maxlength>32</maxlength>
    </
username>
    <
password rules="required|min_length[4]|max_length[32]|xss_clean">
      <
type>password</type>
      <
maxlength>32</maxlength>
    </
password>
    <
fieldset name="Submit">
      <
submit>
        <
type>submit</type>
        <
value>Login</value>
      </
submit>
    </
fieldset>
  </
fieldset>
</
form

Categories: