[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>
<input name="firstname" type="text" id="firstname" value="<?php echo set_value('firstname'); ?>" maxlength=100 />
<?php echo form_error('firstname'); ?>
</p>
<p>
<label for="lastname">Pavardė:</label>
<input name="lastname" type="text" id="lastname" value="<?php echo set_value('lastname'); ?>" maxlength=100 />
<?php echo form_error('lastname'); ?>
</p>
Appreciate any ideas
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:
<?php echo $field_errors['firstname']; ?>