Welcome Guest, Not a member yet? Register   Sign In
form_error not showing errors in view, validation works ok
#1

[eluser]Skiedra[/eluser]
Hi,

I am developing a small app in CI and got stuck. Would appreciate some wisdom.

Problem:
Validation works ok (stops the controller execution based on set_rules condition). Repopulation of fields works OK.
form_error not displaying errors in view, though I can see them errors being generated via $this->form_validation->_error_array

My code (part of it):
Code:
$this->load->library('form_validation');
$this->load->helper(array('form', 'url'));

$this->form_validation->set_rules('firstname', 'Vardo', 'required|xss_clean|prep_for_form|encode_php_tags');

$this->form_validation->set_rules('lastname', 'Pavardės', 'required|xss_clean|prep_for_form|encode_php_tags');


Here is where it stops:
Code:
if ($this->form_validation->run() == FALSE)
{
   $this->_dump($this->form_validation->_error_array);
   $this->load->view('my_app/reg_view', $data);
}

error_array contains errors:

Code:
array(19) {
  ["firstname"]=>
  string(81) "Vardo lauką būtina užpildyti."
  ["lastname"]=>
  string(85) "Pavardės lauką būtina užpildyti."
  ...
}

View snippet:

Code:
<p>
<label for="firstname">Vardas:</label>
&lt;input name="firstname" type="text" id="firstname" value="&lt;?php echo set_value('firstname'); ?&gt;" maxlength=100 /&gt;
&lt;?php echo form_error('firstname'); ?&gt;
</p>

<p>
<label for="lastname">Pavardė:</label>
&lt;input name="lastname" type="text" id="lastname" value="&lt;?php echo set_value('lastname'); ?&gt;" maxlength=100 /&gt;
&lt;?php echo form_error('lastname'); ?&gt;
</p>

Appreciate any ideas Smile

UPDATE:

Managed to track down the ?bug? to form_helper.php line 1000+

Code:
$object = $CI->load->_ci_classes['form_validation'];
        
        [b]if ( ! isset($CI->$object) OR ! is_object($CI->$object))[/b]
        {
        
            return $return;
        }

var_dump($object) returns string(15) "form_validation" in all cases

UPDATE with partial solution:

This is what I did:
1. Add an additional line loading error messages into $data in controller
Code:
if ($this->form_validation->run() == FALSE)
{
$data['field_errors'] = $this->form_validation->_error_array;
$this->load->view('my_app/reg_view', $data);
}

And in view replaced error echo:

Code:
&lt;?php echo $field_errors['firstname']; ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB