Welcome Guest, Not a member yet? Register   Sign In
validation_errors() could not display error message?
#1

[eluser]Julia Yan[/eluser]
--------------controller
if ($this->form_validation->run() == FALSE){
echo "[removed]alert(' ".' input error please redo '."');history.go(-1);[removed]" ;

/* if runing the above line,
it back to page keep current input,
but validation_errors() could not display error message?
*/

/* if do not runing the above line
validation_errors() could display error message,
but lost current input?
*/

}
--------------view

<?php echo validation_errors() ; ?>
...edit form

--------------How can I get both ?
1, validation_errors() display
2, keep current input when page back
#2

[eluser]smilie[/eluser]
Hi,

Please use code tags for readability.

To keep input values in your form do:

In controller:

Code:
# Set all rules - ALSO on the input fields that are not required;
# You _must_ do this to save input data:
$this->form_validation->set_rules('input_field_name', 'Error message', ''); # leave third param empty if input field is not mandatory

# Then do check
if ($this->form_validation->run() == FALSE)
{
    # open the form again (load view)
}
else
{
    # do something else...
}

In your view file:
Code:
$notes = array(
   'name'        => 'notes',
   'value'       => set_value('notes'), # This set_value will preserve your input in case form has errors...
   'style'       => 'width:90%',
);
echo form_textarea($notes);

Cheers,
Smilie
#3

[eluser]Julia Yan[/eluser]
Thanks smilie

I did $this->form_validation->set_rules(...); //this validation_errors() could display error message,
but lost current input?
#4

[eluser]smilie[/eluser]
Please post your whole code here (and please, use code tags!).

Cheers,
Smilie




Theme © iAndrew 2016 - Forum software by © MyBB