I use a specific form in several places. In one of them, I need to ignore the form element that I installed programmatically after validation.
Because this is just an exception, I do not want to create a new form. Therefore, I thought that I would simply delete this element in the controller, for example:
$myForm->remove('myElement');
The problem is that the form will no longer be validated. I am not getting any errors, but $myForm->isValid()just returning an empty value.
$myForm->isValid()
Any ideas what I can do wrong?
Thank!
, , ! ValidationGroup, , . :
ValidationGroup
$form->setValidationGroup('name', 'email', 'subject', 'message'); $form->setData($data); if ($form->isValid()) { ...
, , myElement ValidatorChain. :
$form->getInputFilter()->get( 'myElement' )->getValidatorChain()
, ValidatorChain, . post. ' Zend , , .
, " ", FormFilter. , , , Matthew - , .
@Stoyan Dimov: , BasicForm ExtendedForm. , - . .
class ValidatorChain implements Countable, ValidatorInterface :
class ValidatorChain implements Countable, ValidatorInterface
public function remove($name){ foreach ($this->validators as $key => $element) { $validator = $element['instance']; if($validator instanceof $name){ unset($this->validators[$key]); break; } } }
:
$form->getInputFilter()->get("xxxxx")->getValidatorChain()->remove('xxxxxx');
, .
, , addValidator, :
$element- > addValidator ( ', ');
. , , , .
, , .
zf : http://framework.zend.com/manual/1.12/en/zend.form.elements.html
$form->get('product')->remove('version');
, :
$form->getInputFilter()->get('product')->get('version')->setRequired(FALSE);