CodeIgniter Forums
Form submission using the index function? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form submission using the index function? (/showthread.php?tid=14427)



Form submission using the index function? - El Forum - 01-02-2009

[eluser]Solarpitch[/eluser]
Hey Guys,

I have the following index function that will load the login form when the application is loaded. Is it good practice to submit to the same function when the form is submitted?

Because at the min I need a way to only execute the model call if the form is being submitted or should I create a seperate function exec_login or something?

The login model just returns a row count to check to see if the credentials exist.

Code:
function index(){
    
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->load->model('login_model');
        
                //This will only execute if the form has been submitted...
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $data['result'] = $this->login_model->auth($username, $password);

        $data['form'] = "login_form/form";
        $this->load->view('template/login', $data);
        
    }

login_form/form...
Code:
<?php echo validation_errors(); ?>
<?php echo form_open('index'); ?>
    <table width='420' border='0' cellspacing='2' cellpadding='0' style='font-family:Arial; font-size:12px; font-weight:bold; color:#5A7B00; '>
  <tr>
    <td>Account Username:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&lt;input type='text' name='username' style='width:450px; font-size:23px; color:#999999; ' value="&lt;?php echo set_value('username'); ?&gt;"&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Password:</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&lt;input type='password' name='password' style='width:450px; font-size:23px; color:#999999; '&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>
    &lt;input type='hidden' name='process' value='' /&gt;
    &lt;input type='hidden' name='ip' value=''&gt;
    &lt;input type='image' src='designs/login_bt.jpg' alt='login ' name='process' value='execute'&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
</table>
&lt;/form&gt;



Form submission using the index function? - El Forum - 01-02-2009

[eluser]thinkigniter[/eluser]
What I would do is...
Code:
function _remap(){
  if($this->_logged_in()){
   $this->_continue_loading();
  }else{
   $this->index();
  }
}

This way the override function "_remap()" tests to see if your logged in and inf it's isn't then it loads "index()" and executes the sql querys via the model.

I hope this answers your question?

Cheers