[eluser]keevitaja[/eluser]
[quote author="keevitaja" date="1283101335"]if the form doesn't validate, i can only call a function where form was sent in order to get the error messages. i would like to redirect the page...
Code:
function index() {
//output form
}
function send_data {
redirect(index);
}
in that case i don not get the errors... is it possible to fix it? i like to let people refresh the page without sending the form data again![/quote]
i figured it out. in case someone else has the same problem. flashdata is the solution>
Code:
<?php
class Test extends Controller {
function __construct() {
parent::Controller();
$this->load->library('form_validation');
}
function index() {
echo form_open('test/send');
$input_1 = array(
'name' => 'name_1',
'id' => 'name_1',
'type' => 'text'
);
$input_2 = array(
'name' => 'name_2',
'id' => 'name_2',
'type' => 'text'
);
echo form_input($input_1);
echo form_input($input_2);
echo form_submit(array('value' => 'send'));
echo form_close();
if($errors = $this->session->flashdata('validation_errors')) {
echo '<hr>';
echo $errors;
}
}
function send() {
$this->form_validation->set_rules('name_1', 'Name 1', 'required');
$this->form_validation->set_rules('name_2', 'Name 2', 'required');
if($this->form_validation->run() == false) {
$this->session->set_flashdata('validation_errors', validation_errors('<p>'));
redirect('test');
} else {
echo anchor('test', 'tagasi');
}
}
}