Problems with setRequired and ZendForm

For programming and general questions on Zend Framework
Post Reply
viniciuswebdev
Posts: 2
Joined: Tue Nov 20, 2012 2:14 am

Problems with setRequired and ZendForm

Post by viniciuswebdev » Tue Nov 20, 2012 2:19 am

Hello!

My form is working fine, but the setRequired not working, he is submitting empty values...

Help? Many Thanks !!!

Code: Select all

<?php

class Application_Form_Login extends Zend_Form
{

    public function init()
    {
            	
    	$login = new Zend_Form_Element_Text('login_user');
    	$login->setRequired(true)
      	      ->setAttribs(array('class'=>'input-block-level'))
    	      ->setLabel('nome de usuário:');
    	    	
    	$password = new Zend_Form_Element_Password('password_user');
    	$password->setRequired(true)
    	         ->setAttribs(array('class'=>'input-block-level'))
    	         ->setLabel('senha:');
    	
		$submit = new Zend_Form_Element_Submit('Acessar');
		$submit->setAttrib('class', 'btn btn-large btn-success');
    	
    	$this->addElements(array($login, $password, $submit));
    	
    }
}

us2rn4m2
Posts: 49
Joined: Mon Jun 18, 2012 12:41 am

Re: Problems with setRequired and ZendForm

Post by us2rn4m2 » Tue Nov 20, 2012 8:55 am

Hello,

For ZF1

In your Controller add:

Code: Select all

$request = $this->getRequest();

if($request->isPost()) {
      if($form->isValid($request->getPost())) { 
              your instruction ....
                  
}
http://bit.ly/TattooEdit

viniciuswebdev
Posts: 2
Joined: Tue Nov 20, 2012 2:14 am

Re: Problems with setRequired and ZendForm

Post by viniciuswebdev » Tue Nov 20, 2012 1:04 pm

working! many thanks!!

Post Reply