[eluser]RickRaven[/eluser]
Hi, i am new to CodeIgniter, and currently i am working with the form validation class. However it seems it doesnt work for me.
Here is the code i am working with :
Controller
Code:
public function register()
{
$this->load->library("form_validation");
$this->form_validation->set_rules("firstname","Firstname","required");
$this->form_validation->set_rules("lastname","Lastname","required");
$this->form_validation->set_rules("username","Username","required");
$this->form_validation->set_rules("email","E-Mail","required");
$this->form_validation->set_rules("email-validate","Re-Enter E-Mail","required");
$isPostBack = $this->input->post("isPostBack");
if($isPostBack=="true")
{
if($this->form_validation->run()==TRUE)
{
//database operations will be here
redirect("page/display/userRegistrationSuccessful");
}
}
$this->load->helper("url");
$this->load->helper("form");
$this->load->helper("style");
$page["menu"] = $this->load->view("menu","", true);
$page["top"] = $this->load->view("search_area", "", true);
$page["content"] = $this->load->view("user/registration","", true);
$page["title"] = "Registration";
$page["theme"] = "default";
$page["styles"] = array("main", "menu", "search_area", "user/registeration");
$this->load->view("layouts/default", $page);
}
View
Code:
<div id="registration">
<form method="post">
<fieldset>
<legend>User Registration<legend>
<ul>
<li><?=form_error("firstname")?></li>
<li><span id="label">Firstname : </span><input type="text" id="firstname" maxlength="20" value="<?=set_value("firstname")?>" /></li>
<li><?=form_error("lastname")?></li>
<li><span id="label">Lastname : </span><input type="text" id="lastname" maxlength="20" value="<?=set_value("lastname")?>" /></li>
<li><?=form_error("username")?></li>
<li><span id="label">Username : </span><input type="text" id="username" maxlength="20" value="<?=set_value("username")?>" /></li>
<li><?=form_error("email")?></li>
<li><span id="label">E-Mail : </span><input type="text" id="email" maxlength="60" value="<?=set_value("email")?>" /></li>
<li><?=form_error("email-validate")?></li>
<li><span id="label">Re-enter E-mail : </span><input type="text" id="email-validate" maxlength="60" value="<?=set_value("email-validate")?>" /></li>
<li><input type="submit" id="register" value="Register" /></li>
</ul>
<input type="hidden" name="isPostBack" value="true" />
</fieldset>
</form>
</div>
When i test this code, it never validates even if you fill the all fields. It is displayed with form errors that saying "field is required". Also all fields become empty so set_value function does not work.
I couldn't find the problem. Please guide me to find the solution.