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

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.

function index(){
        $this->load->helper(array('form', 'url'));
                //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);

<?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; '>
    <td>Account Username:</td>
    <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>&lt;input type='password' name='password' style='width:450px; font-size:23px; color:#999999; '&gt;&lt;/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>

What I would do is...
function _remap(){

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?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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