How can I validate the input data from a form that created without using CodeIgniter's form ?
My form looks like this :
<form method="POST" name="frmNewUser" action="<?php echo site_url('users/signup'); ?>" id="contact">
<div class="lable">
<div class="col_1_of_2 span_1_of_2"><input name="u_fname" type="text" class="text" value="First Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'First Name';}" id="active"></div>
<div class="col_1_of_2 span_1_of_2"><input name="u_lname" type="text" class="text" value="Last Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Last Name';}"></div>
<div class="clear"> </div>
</div>
<div class="lable-2">
<input name="u_email" type="text" class="text" value="your@email.com " onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'your@email.com ';}">
<input name="u_pwd" type="password" class="text" value="Password " onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Password ';}">
</div>
<h3>By creating an account, you agree to our <span class="term"><a href="#">Terms & Conditions</a></span></h3>
<div class="submit">
<input type="submit" name="submit" id="submit" value="Submit" >
</div>
<div class="clear"> </div>
</form>
And here is my controller :
function signup(){
$this->load->library('form_validation');
$u_fname = $this->input->post('u_fname');
$u_lname = $this->input->post('u_lname');
$u_email = $this->input->post('u_email');
$u_pwd = $this->input->post('u_pwd');
$this->form_validation->set_rules( $this->input->post('u_fname'), 'First Name', 'required');
if($this->form_validation->run() == FALSE){
echo "error";
}
}
However the run() function of form_validation returns FALSE even though u_fname has input value. How can I grab the data from the form with post method and validate the data using form_validation from CodeIgniter ?
Thank you
</div>
Problem solved. I just need to change
$this->form_validation->set_rules( $this->input->post('u_fname'), 'First Name', 'required');
to
$this->form_validation->set_rules('u_fname', 'First Name', 'required');
previous one passed the value to the function meanwhile the new one passed the "name" of the object.