File/view/lib/helpers/active_record_helper.php

Description

Active record helpers

Makes it easier to create forms for records kept in instance variables.

Functions
error_message_for ($object_name, $object, $options = array())

Returns a string with a div containing all the error messages for the $object whose form elements are prefixed by $object_name.

This div can be tailored by the following options:

  • header_tag - Used for the header of the error div (default: h2)
  • id - The id of the error div (default: form-errors)
  • class - The class of the error div (default: form-errors)

error_message_on ($method, $object, $prepend_text = '', $append_text = '', $div_class = 'form-error')

Returns a string containing the error message attached to the $method on the $object, if one exists. This error message is wrapped in a DIV tag, which can be specialized to include both a prepend_text and append_text to properly introduce the error and a css_class to style it accordingly.

Examples ($post has an error message "is required" on the title attribute):

 error_message_on('title', $post);
 // could generate :
  <div class="form-error">is required</div>
 error_message_on('title', $post, 'The Title field', '(you fool !)', 'input-error');
 // could generate :
  <div class="input-error">The Title field is required (you fool !)</div>

error_wrapping ($tag, $has_error)
form ($object_name, $object, $options = array())

Returns an entire form with input tags and everything for a specified ActiveRecord object.

Example ($post is a new record that has a title using VARCHAR and a body using TEXT):

 form('post', $post);
 // could generate :
  <form method="post" action="/posts/create">
   <p>
     <label for="post_title">Title</label>
     <input type="text" id="post_title" name="post[title]" value="" />
   </p>
   <p>
     <label for="post_body">Body</label>
     <textarea name="post[body]" id="post_body"></textarea>
   </p>
   <input type="submit" name="submit" value="Create" />
 </form>

It's possible to specialize the form by providing action, submit_value and include HTML block.

Example :

 form('product', $product, array('action' => 'register', 'submit_value' => 'Save',

input ($object_name, $method, $object, $options = array())

Returns a default input tag for the type of object returned by the method.

Example (title is a VARCHAR column and holds "Hello World"):

 input('post', $post, 'title');
 // could generate :
  <input type="text" id="post_title" name="post[title]" value="Hello World !" />

Documentation generated on Wed, 24 Jan 2007 15:00:04 +0100 by phpDocumentor 1.3.0RC4