Skip to content

forms validation

Harmen Janssen edited this page Aug 11, 2016 · 2 revisions

Validation

Security

Add 'confirm password' validation

Adding extra validators

Zend provides tons of validators that can all be used with the form package. See http://framework.zend.com/manual/en/zend.validate.html for the full list.

Some examples:

// only allow alphanumeric input
$form->addElement('text', 'username', array(
	'label' => 'Your username',
	'validators' => array('alnum')
));
// allow digits between 12 and 42
$form->addElement('text', 'anumber', array(
	'validators' => array('digits', array('between', array('min' => 12, 'max' => 42)))
));
?>

Anti-spam measures

Note that Garp_Form automatically adds a honeypot and timestamp-based validation to the form. In general you should want this since it's A Good Thing™ but on the rare occasion you do not wish to use these you should remove them manually:

$form->removeElement(Garp_Form::TIMESTAMP_FIELD_KEY);
$form->removeElement(Garp_Form::HONEYPOT_FIELD_KEY);
?>
Clone this wiki locally