![]() |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi all,
I have 4 different sets of Zend_Form_Element_MultiCheckbox that I can't combine into one. My problem is that I want to validate these 4 different sets as one and say 'At least one of the checkboxes must be selected'. I know I need to create a custom validator but could someone give me a pointer on how I then apply this to the 4 separate Zend_Form_Element_MultiCheckbox instances as one? Cheers, Tom |
|
|||
|
Thanks for the input Adrian.
Unfortunately it appears even if I apply a custom validator to each of the sets of checkboxes, if no checkboxes are selected then none of the validators get called. My current solution would be to apply a validator to a random element (the submit button for example) and check the state of the checkboxes from there. But surely there's a better way? |
|
|||
|
This is the code currently by the way...
Code:
class BBC_Buzzpage_ReportForm extends Zend_Form {
public function __construct() {
$offensive = new Zend_Form_Element_MultiCheckbox('o');
$offensive->setLabel("O...")
->addMultiOptions(array(
'0' => 'P',
'1' => 'H',
'2' => 'G'
));
$unlawful = new Zend_Form_Element_MultiCheckbox('u');
$unlawful->setLabel("U...")
->addMultiOptions(array(
'0' => 'C',
'1' => 'B',
'2' => 'D',
'3' => 'H',
'4' => 'D'
));
$accessSafety = new Zend_Form_Element_MultiCheckbox('a');
$accessSafety->setLabel("P...")
->addMultiOptions(array(
'0' => 'P',
'1' => 'S',
'2' => 'S',
'3' => '1',
'4' => 'F',
'5' => 'S'
));
$promotional = new Zend_Form_Element_MultiCheckbox('p');
$promotional->setLabel("Pr")
->addMultiOptions(array(
'0' => 'S',
'1' => 'P',
'2' => 'C',
'3' => 'C'
));
$value = new Zend_Form_Element_MultiCheckbox('v');
$value->setLabel("L...")
->addMultiOptions(array(
'0' => 'S'
));
$reason = new Zend_Form_Element_Text('r');
$reason->setLabel("Use this box to give us more details on your reason:");
$submit = new Zend_Form_Element_Submit('Submit');
$this->addElements(array(
$o,
$u,
$a,
$p,
$v,
$r
));
$this->setMethod("post");
$this->clearDecorators();
$this->setDecorators(array(array('ViewScript', array(
'viewScript' => 'path/to/form/reportform.phtml',
'class' => 'form element'
)), 'Form'));
}
}
Last edited by ro88o; 01-29-2010 at 04:06 PM. |
|
|||
|
$element->setAllowEmpty() is probably what you need.
Validate Empty when other field is true |
|
|||
|
Sorry for the slow reply guys I had to work on something else for a few days, thanks alot for your help.
setAllowEmpty(true) has forced my custom validator to run on the checkboxes as required, however I expected to be able to validate the multicheckbox element as a whole rather than each individual checkbox. How do I get access to the other form elements whilst in the validator for a checkbox? I echoed $this while in the validator and it just returned: Code:
object(App_Validate_OOC)[84]
protected '_value' => string 'accepted' (length=8)
protected '_messageVariables' =>
array
empty
protected '_messageTemplates' =>
array
empty
protected '_messages' =>
array
empty
protected '_obscureValue' => boolean false
protected '_errors' =>
array
empty
protected '_translator' => null
protected '_translatorDisabled' => boolean false
public 'zfBreakChainOnFailure' => boolean false
|
|
|||
|
Quote:
Code:
public function isValid($value, $formData) {...}
Code:
public function isValid($value) {...}
Last edited by maciek.231; 02-05-2010 at 10:38 AM. |
|
|||
|
Values is fine, as long as I can check them I can do what I want. But if I use the isValid above with the $formData included it throws an exception saying it must be compatible with Zend_Validate_Interface::isValid()?
|
|
|||
|
That is strange. Have you put "public function" or just "function"? I see I forgot the keyword "public".
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| Designed by: Miner Skinz |
Powered by vBulletin® Version 3.8.4 Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Search Engine Friendly URLs by vBSEO 3.1.0 |
![]() |