Skip to content

Instantly share code, notes, and snippets.

@smolak
Created May 16, 2013 21:19
Show Gist options
  • Save smolak/5595192 to your computer and use it in GitHub Desktop.
Save smolak/5595192 to your computer and use it in GitHub Desktop.
ZFCRUD users form.
<?php
class Aadmin_Form_Users extends Zend_Form
{
public function init()
{
/**
* You would probably like to add some more filters / validators
* to check all things. This is meant only to be a simple example.
*/
$name = new Zend_Form_Element_Text('name');
$name->setRequired()
->addFilter('StringTrim')
->addValidator('NotEmpty', true)
->setLabel('Name');
$this->addElement($name);
$vDbNoRecordExist = new Zend_Validate_Db_NoRecordExists(
array(
'table' => 'users',
'field' => 'login'
)
);
$login = new Zend_Form_Element_Text('login');
$login->setRequired()
->addFilter('StringTrim')
->addValidator('NotEmpty', true)
->addValidator($vDbNoRecordExist, true)
->setLabel('Login');
$this->addElement($login);
$password = new Zend_Form_Element_Password('password');
$password->setRequired()
->addValidator('NotEmpty', true)
->setLabel('Password');
$this->addElement($password);
$vIdentical = new Zend_Validate_Identical('password');
$repeatPassword = new Zend_Form_Element_Password('password_repeat');
$repeatPassword->setRequired()
->setIgnore(true)
->addValidator('NotEmpty', true)
->addValidator($vIdentical, true)
->setLabel('Repeat password');
$this->addElement($repeatPassword);
$email = new Zend_Form_Element_Text('email');
$email->setRequired()
->addFilter('StringTrim')
->addValidator('NotEmpty', true)
->addValidator('EmailAddress', true)
->setLabel('Email');
$this->addElement($email);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Create new user')
->setIgnore(true);
$this->addElement($submit);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment