Hi guys, I'm trying to figure out how to get this zend form to validate. I don't understand:
Are the addValidator() arguments specific validators? Is there a list somewhere of those validators?
I've got this in the forms/contact.php:
class Application_Form_Contact extends Zend_Form {
public function init()
{
$this->setAction('index/process');
$this->setMethod('post');
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name:');
// $name->addValidator('alnum');
$name->setRequired(true);
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email:')->setRequired(true);
$confirm = new Zend_Form_Element_Text('confirm');
$confirm->setLabel('Confirm Email:')->setRequired(true);
$phone = new Zend_Form_Element_Text('phone');
$phone->setLabel('Phone:')->setRequired(true);
$subject = new Zend_Form_Element_Select('subject');
$subject->setLabel('Subject:')->setRequired(true);
$subject->setMultiOptions(array('Performance'=>'Performance',
'Workshop'=>'Workshop',
'Other'=>'Other'
));
$message = new Zend_Form_Element_Textarea('message');
$message->setLabel('Message:')->setRequired(true);
$message->setAttrib('rows','6');
$message->setAttrib('cols','30');
$submit = new Zend_Form_Element_Submit('Submit');
$this->addElements(array( $name,
$email,
$confirm,
$phone,
$subject,
$message,
$submit
));
$this->setElementDecorators(array
('ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label' , array('tag' => 'td')),
array(array('row' => 'HtmlTag') , array('tag' => 'tr'))
));
$submit->setDecorators(array('ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'PREPEND')),
array(array('row' => 'HtmlTag') , array('tag' => 'tr'))
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag' , array('tag' => 'table' , 'class' => 'formTable')),
'Form'
)
);
}
}
my controller is:
public function indexAction()
{
$this->view->form = new Application_Form_Contact();
}
public function processAction()
{
// $this->view->form = new Application_Form_Contact();
//
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
// echo 'success';
$this->view->data = $formdata;
} else {
// $form->populate($formData);
}
}
I'm a newbie, so I'm probably making some obvious errors that I don't see. I'm trying to do basic validation:
- all fields must be filled out
- all html gets stripped
- email and confirm
- email fields must match
- email must be valid format.
Any help would be greatly appreciated!