Apply for Zend Framework Certification Training

Codeigniter




                                           Controller user.php
<?php
class user extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
	}
	function index()
	{
		$this->load->library('form_validation');
		$this->form_validation->set_rules('fname','First name','required|min_length[5]');
		if($this->form_validation->run()==FALSE)
		{
			$this->load->view('login');
		}
	}
}
                                  View	login.php
<?php echo form_open('user/index');	?>
<?php echo form_input(array('id'=>'fname','name'=>'fname'));?><?php echo form_error('fname')?>
<?php echo form_submit(array('id'=>'submit','name'=>'submit','value'=>'Data Post'))?>

                                Some more validation Rules
$this->form_validation->set_rules('dname', 'Username', 'required|min_length[5]|max_length[15]');
$this->form_validation->set_rules('demail', 'Email', 'required|valid_email');
$this->form_validation->set_rules('dmobile', 'Mobile No.', 'required|regex_match[/^[0-9]{10}$/]');
$this->form_validation->set_rules('daddress', 'Address', 'required|min_length[10]|max_length[50]');


Note :- If you want to search the uniqueness  in field in Table 

$this->form_validation->set_rules('username', 'Username',
           'required|min_length[5]|max_length[12]|is_unique[users.username]');
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');

The above code sets the following rules:
1.	The username field be no shorter than 5 characters and no longer than 12.
2.	The password field must match the password confirmation field.
3.	The email field must contain a valid email address.
 
                                    

< First How to retrieve second maximum salary in Mysql >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top