• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form submission using the index function?

#1
[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;


Messages In This Thread
Form submission using the index function? - by El Forum - 01-02-2009, 08:02 AM
Form submission using the index function? - by El Forum - 01-02-2009, 05:23 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.