CodeIgnitor: How the view get loaded automatically for the form page? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

CodeIgnitor: How the view get loaded automatically for the form page?

<?php class Form_valid extends CI_Controller { function index() { $this->load->helper(array('form','url')); $this->load->library('form_validation'); $this->form_validation->set_rules('user',"User Name","required"); $this->form_validation->set_rules('password',"Password","required"); $this->form_validation->set_rules('confirm_password',"Confirm Password","required"); $this->form_validation->set_rules('email',"Email","required"); if($this->form_validation->run() == FALSE) { $this->load->view('example23)/form_view'); } else { $this->load->view('example23)/form_success'); } } } ?> // As you can see in the above , i haven't loaded my view file,like : $this->load->view('example23)/form_view'), than how this view file gets loaded at the start of the execution of the program. Is it because, since there no input in intial. So, the run() method returns false and hence , the view gets loaded and after providing the data and clicking the submit button, the run() method returns TRUE , since the validation is set now as data is provided . So, it will load the form_success view page? Please answer

23rd May 2018, 2:49 PM
Saurav Kumar
Saurav Kumar - avatar
1 Answer
0
This is index function. Let your views load from index. Make another function submit and put code from index function to submit function. Now when you'll load url.com/Form_valid/ your initial form view page will load. Add value of action attribute as action="url.com/Form_valid/submit" Now when form is submitted, your function will run, validate form show new view according to if else.
27th Mar 2019, 9:06 AM
Kawalpreet Juneja
Kawalpreet Juneja - avatar