We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How I can remove element form or validator?

How I can remove element form or validator?



9.2k

Also I want to have a form method getElements



9.2k

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.



9.2k

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;

}



98.9k

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



9.2k

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.



9.2k

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 { var_dump($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?



98.9k

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.



9.2k

Awesome! Great tech support! Thanks!



9.2k

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



9.2k

Hm, and method "remove" does not work



98.9k

Sorry, can you check again with 1.0.1?



9.2k

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?