Zend Custom Error Message for Flags

I have a form on a Zend-based website that has a mandatory "Terms of Use" checkbox.

I installed a custom message that says: "You must agree to the terms."

however, since the checkbox "availability =" is required ", it returns

Field 'terms' is required by rule 'terms', but the field is missing 

which is this constant defined in the framework of Zend:

 self::MISSING_MESSAGE => "Field '%field%' is required by rule '%rule%', but the field is missing", 

I could edit this constant, but it would change the error report for all the necessary flags.

How can I influence the error report in this particular case?

+4
source share
2 answers

You can override the default message as follows:

 $options = array( 'missingMessage' => "Field '%field%' is required by rule '%rule%', dawg!" ); 

And then:

 $input = new Zend_Filter_Input($filters, $validators, $myData); 

Or

 $input = new Zend_Filter_Input($filters, $validators, $myData); $input->setOptions($options); 

... and finally:

 if ($input->hasInvalid() || $input->hasMissing()) { $messages = $input->getMessages(); } 

He mentioned on the Zend_Filter_Input manual page.

+3
source

If you use Zend_Form_Element_Checkbox , you can configure error messages on the Zend_Validate validators .

 $form->addElement('checkbox', 'terms', array( 'label'=>'Terms and Services', 'uncheckedValue'=> '', 'checkedValue' => 'I Agree', 'validators' => array( // array($validator, $breakOnChainFailure, $options) array('notEmpty', true, array( 'messages' => array( 'isEmpty'=>'You must agree to the terms' ) )) ), 'required'=>true, ); 

You want to make sure that the unblocked value is empty and that the field is required

+12
source

All Articles