$form = \Fieldset::instance(); $form->add('name', 'Name'); $form->add('phone', 'Phone')->add_rule('required');; $form->add('email', 'Email')->add_rule('valid_email'); $form->add('message', 'Message', array('type'=>'textarea')); $form->add('submit', '', array('type'=>'submit', 'value'=>'Send', 'class'=>'btn medium primary')); $this->view->set('form', $form->build(), false);The form comes up great, and I can list out the error messages by iterating through $form->validation()->errors(). However, I was expecting each field with an error to have the error_class specified in the form config. So, if for example the user types in an invalid email address, I would expect the form to come back with class="validation_error" in the table cells for the email field. Unfortunately, this doesn't happen. The class for the table cells stay empty. It seems like there's a problem in the Fieldset_Field class. Maybe at line 460? From what I can tell, this is where the logic for this is at, and the error() method is returning false even when there's actually an error for the field. Or maybe I'm wrong about how this should work?
public function action_index() { $form = \Fieldset::instance(); $form->add('name', 'Name'); $form->add('phone', 'Phone')->add_rule('required');; $form->add('email', 'Email')->add_rule('valid_email'); $form->add('message', 'Message', array('type'=>'textarea')); $form->add('submit', '', array('type'=>'submit', 'value'=>'Send', 'class'=>'btn medium primary')); //DON'T BUILD THE FORM BEFORE RUNNING VALIDATION... //$this->view->set('form', $form->build(), false); if($form->validation()->run() == true) { } //BUILD IT AFTERWORDS INSTEAD... $this->view->set('form', $form->build(), false); }
if (\Input::post()) { if ($form->validation()->run()) { // save the data and redirect away } else { // post validation actions if needed } } // load the formIn your case probably not an issue, but if you have post validation code, you obviously want to run that only if there was something to validate, not at the initial load of the form.
It looks like you're new here. If you want to get involved, click one of these buttons!