GoodForm


GoodForm DMZ Extensions

GoodForm comes with its own Datamapper DMZ edition. This makes drawing a form for any Datamapper model as easy as $object->form()... and handling a POST request from the form with $object->post_form()!

form (object &goodform [, array fields])

Example:

$gf = new Goodform();
		
$u = new User();

$u->get_by_id($user_id);

$u->form($gf, array('name', 'email', 'password'));

$gf->submit('do_login', 'Login');

$form = $gf->generate('users/login');

post_form ([array fields])

Example:

$gf = new Goodform();
		
$u = new User();

$u->get_by_id($user_id);

if (isset($this->input->post('do_update')))
{
	$u->post_form();
	
	if($u->save())
		// handle success
	else
		// handle error
}

Make sure you call form() after post_form(), save() and anything that could change a field value.

Any validation errors will be automatically added next to the relevant form field.

options ([boolean include_null])

This method returns an option array for the model. Used to create dropdown fields for a set of records.

Example:

$gf = new Goodform();

$u = new User();

// get subset of user records
$u->get_by_group('admin');

// field spec
$spec = array(
	'name' => 'admin_user',
	'label' => 'Select Administrator',
	'options' => $u->options()	
);

// add dropdown to form
$gf->dropdown($spec);

The options array will use the records id as the value and call the models __toString() method as the options string.