How I can remove element form or validator?

How I can remove element form or validator?



6.0k

Also I want to have a form method getElements



6.0k

I have a complex form, which on certain conditions may vary. Some fields are removed, some validators change. And at the moment, for me, this object is very difficult. Even if I just do not make any unnecessary items, in the Temple I can not verify their existence, to know which block to bring and what not.



6.0k

I disagree. In this issue is a question of an error message, and I'm talking about removing the validator or form element. Or even be the verification of the existence of a form element.



368

You cannot remove element from form

To remove any custom validations you must override get messages. public function getMessages() { // If you want to remove all $this->_messages = array(); /// to remove one element crate custom logic

return $this->_messages;

}



82.7k

Why do you need to remove an element from the form?



6.0k

I wanted to do, by analogy with Zend. To make the form and bring it through the echo $ form->render(), and then depending on the delete some items. But now I realized that I needed something to do with the template, because to remove items from the form is not enough, you also need to not try to take them in template.



6.0k

I still do not understand how to do. Let's say I need in some cases to turn off specific validators. I have a code like this: public function indexAction () { $model = new \Model(); $form = $model->getForm();//return Phalcon\Forms\Form if($this->request->isPost()){ if($form->isValid($POST)){ $model->save(); } else { vardump($form->getMessages());die; } } }

My form has a validator, and the model, no, I was validating data form and it is in it I need to disable the validators, so replacement method getMessages (), the model does not help me. Maybe I was not the correct action?



82.7k

I added a Phalcon\Forms\Form::remove (to remove an existing element from the form) and Phalcon\Forms\Form::has (to check if an element has been added to the form) in the 1.0.1 branch. Hope this help you.



6.0k

Awesome! Great tech support! Thanks!



6.0k

Method "has" return "false" if element exists and return "true" if not



6.0k

Hm, and method "remove" does not work



82.7k

Sorry, can you check again with 1.0.1?



6.0k

Thank you. Now is ok.

So as I see, functionality to remove element from form is added. But at this moment I need to remove some validators from element. And I think this question is still open. So is it possible to remove validator from form element?