[eluser]mjstenbe[/eluser]
Hi,
Im new to CI and am currently learning the system and its capabilities. I was reading through the documentation and tried to implement a simple form with validation. The basic functionality seems to be working ok, but I cant seem to get any output from form_error() function to display field spesific errors? The $this->validation->error_string does work fine, however, and prints out all the errors at once. Whats wrong here?
Below is my code for the view.
Code:
<h1>Entering user data</h1>
<?php echo $this->validation->error_string;?>
<?php echo form_open('validator');?>
<?php echo '<p>'.form_error('firstname').'</p>'; ?>
<p>First Name <input type="text" name="firstname" value="<?php echo set_value('firstname');?>" size="50" /></p>
<p><input type="submit" value="Send Data" /></p>
</form>
And here's the controller:
Code:
class Validator extends Controller {
function Validator() {
// load controller parent
parent::Controller();
// load 'url' helper
$this->load->helper('url');
// load 'form' helper
$this->load->helper('form');
// load 'validation' class
$this->load->library('validation');
}
function index() {
// set validation rules
$rules['firstname']="required|min_length[6]|max_length[15]|trim|xss_clean";
$rules['lastname']="required|min_length[6]|max_length[15]|trim|xss_clean";
$rules['email']="required|valid_email|trim|xss_clean";
$this->validation->set_rules($rules);
// check if form has been submitted properly
if ($this->validation->run()==FALSE) {
// redisplay web form
$this->load->view('form_view');
}
// display success web page
else {
$this->load->view('success_view');
}
}
}
Thanks for any help.