Search code examples
phpphalconvolt

How to clear form in volt view after submit?


This is the view before submit :

enter image description here

After i fill the form and submit it, the entry records still there when i using volt.

enter image description here

how can i clear it ? This is my Form :

class BataorderForm extends \Phalcon\Forms\Form{
    public function initialize(){

        $protComsId   = new Select('protComsId',CompanyMaster::find(),[
            'class'         => 'btn btn-default btn-block',
            'using'         => ['comsId','comsName'],
            'useEmpty'      => true,
            'emptyText'     => '-- Choose Company --',
            'emptyValue'    => ''
        ]);
        $protComsId->setLabel('Company Master');
        $this->add($protComsId);
}

Solution

  • To reset every element in a form you have to call the method clear()

    Example controller usage:

    $form = new YourForm();
    if ($this->request->isPost() AND $this->security->checkToken() AND $form->isValid($this->request->getPost())) {
        // Form is valid
    } else {
        // Form is not valid. Let's reset it to annoy our user :)
        $form->clear();
    }
    $this->view->form = $form;
    

    More info on form methods in the Documentation.