php - How to validate a form in codeigniter -
i using code igniter 2.1.0 ad trying validate form(though form found homepage of website), have followed documentation on not seem work expected.each time include library page re arranges itself. please 1 tell me wrong.beow portion of page trying vaidate.
<?php echo validation_errors(); ?> <form id="signup" action="" method="get"> <label> username:<input type="text" name="username" value="" size="31"/> </label> <br> <label> email:<input type="text" name="email" values="" size="31"/> </label> <br> <label> password:<input name="password" type="password" value="" size="31"/> </label> <br> <label> confirm password:<input name="passcon" type="password" value="" size="31"/> </label> <br> <label> date of birth:<input type="date" name="dob" value="" size="31" /> </label> <br> <input type="radio" name="sex" value="male" /> male<br /> <input type="radio" name="sex" value="female" /> female <br> <input id="button" type="submit" value="signup" /> </form>
first must include form_validation library controller:
$this->load->library('form_validation');
second need specify restrictions:
$this->form_validation->set_rules('username','username','required|trim|minlength[6]'); $this->form_validation->set_rules('password','password','required'); etc..
third need submit form in case of every thing went correctly:
if($this->form_validation->run()){ // requirement met }else{ // not requirement met }
Comments
Post a Comment