How to set an form error in the action. symfony 1.4


I have a field (company_abn).

I validate this field via web services in the action, so I need to set an error message in the action.

Here is how I did it..

            $register_parameters = $request->getParameter('user');
            $this->form->bind( $register_parameters );
            //do your abn validation stuff

            if(!$abn_valid){
                //set the value of the 'company_abn' field to invoke the 'required' error message
                $register_parameters['company_abn'] = '';
                //rebind the form to make it so that, isValid() will = false
                $this->form->bind( $register_parameters );
                //set your new error message for this widget
                $this->form->getValidator('company_abn')->setMessage('required', 'Your ABN is not Valid');

             }
  1. #1 by Guilherme Veras on August 18, 2010 - 08:09

    very nice =) thanks!

  2. #2 by laci on April 28, 2011 - 23:44

    Very good it helps me, but in my case i must call $this->form->getValidator(… before i bound the form to make it work.

(will not be published)