Creating the User Form

Now you're ready to create the user form. Create a new file in application/forms named User.php, and then create the new user form, as shown in Listing 8-4.

Listing 8-4. The User Form in application/forms/User.php <?php class Form_User extends Zend_Form {

public function init() {

$this->setMethod('post'); // create new element

$id = $this->createElement('hidden', 'id'); // element options

$id->setDecorators(array('ViewHelper')); // add the element to the form $this->addElement($id);

//create the form elements

$username = $this->createElement('text','username'); $username->setLabel('Username: '); $username->setRequired('true'); $username->addFilter('StripTags');

$username->addErrorMessage('The username is required!'); $this->addElement($username);

$password = $this->createElement('password', 'password'); $password->setLabel('Password: '); $password->setRequired('true'); $this->addElement($password);

$firstName = $this->createElement('text','first_name'); $firstName->setLabel('First Name: '); $firstName->setRequired('true'); $firstName->addFilter('StripTags'); $this->addElement($firstName);

$lastName = $this->createElement('text','last_name'); $lastName->setLabel('Last Name: '); $lastName->setRequired('true'); $lastName->addFilter('StripTags'); $this->addElement($lastName);

$role->setLabel("Select a role:"); $role->addMultiOption('User', 'user'); $role->addMultiOption('Administrator', 'administrator'); $this->addElement($role);

$submit = $this->addElement('submit', 'submit', array('label' => 'Submit'));

Was this article helpful?

0 0

Post a comment