GoodForm


Preparing your models

You can customise your model forms, specifiying their input type, tooltip and other attributes.

  1. Open up the model in a text editor.
  2. Edit the models vaidation array and add any of the following attributes to each field.
    • type: the form element this field will use. text is used by default
    • label: the label for this form element.
    • description: a tooltip description of this field.
    • Plus any other HTML attribute you wish to include in the form element. e.g. class, id, title, disabled
  3. Save your model.

Passing a field type of FALSE will force goodform to ignore the field when building a form.

Example

class Person extends Datamapper {
			
	var $validation = array(		
		'id' => array(
			'rules' => array(),
			'label' => 'ID',
			'type'	=> 'hidden'
		),
		'first_name' => array(
			'rules' => array('required', 'max_length' => 128),
			'label' => 'First Name',
			'type'	=> 'text',
			'description' => '',			
			'size' => 30,
			'maxlength' => 128,
			'search' => 'string'
		),
		'last_name' => array(
			'rules' => array('required', 'max_length' => 128),
			'label' => 'Last Name',
			'type'	=> 'text',
			'description' => '',			
			'size' => 30,
			'maxlength' => 128,
			'search' => 'string'
		),
		'date_of_birth' => array(
			'rules' => array(),
			'label' => 'Date of Birth',
			'type'	=> 'text',
			'table' => 'mysqldatetime_to_date[d/m/y]',
			'description' => 'Date format YYYY-MM-DD',		
			'size' => 20,
			'class' => 'datepicker'
		),		
		'email' => array(
			'rules' => array('required', 'max_length' => 256, 'valid_email'),
			'label' => 'Email Address',
			'type'	=> 'text',
			'description' => 'Please enter a valid email address',			
			'size' => 30,
			'maxlength' => 265,
			'search' => 'string'
		),
		'updated' => array(
			'rules' => array(),
			'label' => 'Updated',
			'type'	=> FALSE,
			'table' => 'mysqldatetime_to_date[d/m/y]',
			'description' => 'When the record was last updated',		
			'size' => 20,
			'class' => 'datepicker'
		),		
		'created' => array(
			'rules' => array(),
			'label' => 'Created',
			'type'	=> FALSE,
			'table' => 'mysqldatetime_to_date[d/m/y]',
			'description' => 'When the record was created',		
			'size' => 20,
			'class' => 'datepicker'
		)
	);