This article mainly introduces the CodeIgniter form verification method, and analyzes the specific steps and implementation skills of CodeIgniter Form Verification Based on the instance form, for more information about CodeIgniter form verification, see the following example. We will share this with you for your reference. The details are as follows:
1. Write a View File myform. php In the Directory D: \ CodeIgniter \ system \ application \ views.
My Form<?php echo $this->validation->error_string;?><?php echo form_open('form/index');?>UsernamePasswordPassword ConfirmEmail Address
Then write a View File formsuccess. php.
My FormYour form was successfully submitted!<?=anchor('form', 'Try it again!'); ?>
2. Write a form. php controller file in the Directory D: \ CodeIgniter \ system \ application \ controllers.
<?phpclass Form extends Controller{ function index(){ $this->load->helper(array('form','url')); $this->load->library('validation'); $rules['username'] = "required"; $rules['password'] = "required"; $rules['passconf'] = "required"; $rules['email'] = "required"; $this->validation->set_rules($rules); // $this->validation->set_error_delimiters('','
'); $fields['username'] = 'Username'; $fields['password'] = 'Password'; $fields['passconf'] = 'Password Confirmation'; $fields['email'] = 'Email Address'; $this->validation->set_fields($fields); if ($this->validation->run()==false) { $this->load->view('MyView/myform'); }else { $this->load->view('MyView/formsuccess.php'); } }}?>
3. Access http: // localhost: 8888/index. php/form/index
OK. The results are all displayed.