2008年12月27日星期六

RE: [fw-mvc] Another Zend_Form checkboxes bug ?

A miss the element name in the validation section in addError() method call, here is the good one:

 

Class SomeForm extends Zend_Form

{

 

public function __construct($options = null)

{

                Your code here

                …

}

 

//override isValid method

public function isValid($data)

{

                $valid = true;

 

                //validate your checkbox according your code below,  if checkbox is checked, value is set to 1

                If ($this->contract->getValue() != 1)

                {

                               $this->contract->addError(‘you must agree our conditions!’);

                               $valid = false;

                }

               

                return parent::isValid($data) && $valid;

}

}

 

Regards,

Jaime.

 

 

De: Jaime Garcia [mailto:jgarcia@vali.com.mx]
Enviado el: Sábado, 27 de Diciembre de 2008 01:43 p.m.
Para: 'Zend Framework MVC'
Asunto: RE: [fw-mvc] Another Zend_Form checkboxes bug ?

 

Hello John,

I think this behavior is expected in checkboxes due the nature of the element (what is defined as empty o required if you can change checked or unchecked value?). however there is a workaround to do this validation without affect your  code outside of your form definition as follows:

 

Class SomeForm extends Zend_Form

{

 

public function __construct($options = null)

{

                Your code here

                …

}

 

//override isValid method

public function isValid($data)

{

                $valid = true;

 

                //validate your checkbox according your code below,  if checkbox is checked, value is set to 1

                If ($this->contract->getValue() != 1)

                {

                               $this->addError(‘you must agree our conditions!’);

                               $valid = false;

                }

               

                return parent::isValid($data) && $valid;

}

}

 

I hope this works for your case.

Best Regards,

Jaime Garcia.

 

De: John Antony Riga [mailto:ja.riga@yahoo.com]
Enviado el: Sábado, 27 de Diciembre de 2008 07:53 a.m.
Para: Zend Framework MVC
Asunto: [fw-mvc] Another Zend_Form checkboxes bug ?

 

Hello everyone !

I'm having a little problem with checkboxes, I'm using this element :
  
    // ACCEPT CONDITIONS
         $this->addElement(
                    'CheckBox',
                    'contract',
                    array(
                        'label'        => 'I accept the terms of service',
                        'style'            =>'margin-left:100px;',
                        'required'   => true,
                        'checkedValue' => '1',
                        'validators'     =>  array(array('NotEmpty', true)),
                    )
                );
       
I need my users to check the checkbox before the can submit the form, but actually it's not the case. Checking the checkbox is not required to validate the form despite what I wrote (require => true) and the form subimts

Is this a bug ? I saw there was a lot of bugs in the checkbox form elements so this might be a new one. Or is this me doing somehting wrong ?
JA.

 

没有评论: