[eluser]esthezia[/eluser]
hello!
i searched for hours on the internet and didn't find a solution for my problem! pls help!
i'm a beginner with codeigniter. my problem is with form validation library. i have a simple form with a few inputs and i want to validate them: some of them are required, some are not. if i don't write anything in any field there should be an error for every empty field that is required, but instead there is only the error for the last validated input!
here's my view:
Code:
<?php echo form_open(); ?>
<div class="section">website title</div>
<ul class="data">
<li class="req"><label>Website title</label><input type="text" name="website" value="<?php echo set_value("website", ""); ?>" /></li>
</ul>
<div class="clear"></div>
<div class="section">admin user</div>
<ul class="data">
<li class="req"><label>Username</label><input type="text" name="username" value="<?php echo set_value("username", ""); ?>" /></li>
<li class="req"><label>Password</label><input type="password" name="password" value="<?php echo set_value("password", ""); ?>" /></li>
<li class="req"><label>Email address</label><input type="text" name="email" value="<?php echo set_value("email", ""); ?>" /></li>
<li><label>First name</label><input type="text" name="first_name" value="<?php echo set_value("first_name", ""); ?>" /></li>
<li><label>Last name</label><input type="text" name="last_name" value="<?php echo set_value("last_name", ""); ?>" /></li>
</ul>
<div class="clear"></div>
<?php echo validation_errors("<p class=\"error\">", "</p>"); ?>
<input type="submit" value="INSTALL" class="submit_btn" />
<?php echo form_close(); ?>
here's the function in my controller that handles the form:
Code:
function index () {
if (!$this->input->post()) {
$this->load->view("install");
return;
}
$this->form_validation->set_rules("website", "website", "required|trim|xss_clean");
$this->form_validation->set_rules("username", "username", "required|trim|alpha_numeric|xss_clean");
$this->form_validation->set_rules("password", "password", "min_length[5]|trim|xss_clean");
$this->form_validation->set_rules("email", "email", "required|trim|valid_email|xss_clean");
$this->form_validation->set_rules("first_name", "first name", "trim|xss_clean");
$this->form_validation->set_rules("last_name", "last name", "trim|xss_clean");
if ($this->form_validation->run() === FALSE) {
$this->load->view("install");
return;
}
$this->load->view("install");
}
if i hit submit, there is no error showing because the last validation rule doesn't contain "required" and thus it is not visible, but if i let only the required rules, it shows only "the email field is required" and that's it.
pls if someone can help me it would be much appreciated!
thank you!