I would like to validate form and if validation passes it has to be submitted to connectTracking Action.
At present form gets submitted to connectTracking action before it passes validation.
Controller:
public function easyAction(){
$auth = Zend_Auth::getInstance();
$user_id = $this->_helper->Utilities->getCurrentUserId();
if ($auth->hasIdentity()) {
$form = new Application_Form_easy();
$form->submit->setLabel('Submit');
$this->view->form = $form;
$formData = $this->getRequest()->getPost();
if ( ($this->getRequest()->getPost('easyform', false)) && ($form->isValid($this->getRequest()->getPost())) ) {
$username = $form->getValue('username');
$password = $form->getValue('password');
$releasedata = array('username' => $username, 'password' => $password);
}
}
}
/application/forms/easy.php
class Application_Form_easy extends Zend_Form {
public function init() {
$this->setMethod('post');
$this->setName('easyform');
$this->setAction('/index.php/releases/connectTracking'); # Submitting to different action
$username = new Zend_Form_Element_Text('username');
$username->setLabel('Username * :')
->setRequired(true)
->addValidator('NotEmpty', true, array('messages' => 'Please enter Username'));
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password * :')
->setRequired(true)
->addValidator('NotEmpty', true, array('messages' => 'Please enter password '));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('id', 'easyform');
$submit->setAttrib('name', 'easyform');
$this->addElements(array($username, $password, $submit));
}
}
Could you please let me know how shall I validate the form and then submit to action
Many Thanks!