• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Would like to condense some code.

#12
[eluser]Damien K.[/eluser]
I've simplified your code to the following. The below code should work for you. Note that I extended the CI_Input class to support a set_post() function that sets data in $_POST.

Code:
function _populate_contact()
{
    if($this->userlib->logged_in())
    {
        $this->load->model('User_model', 'user_m');
        $userid    = $this->session->userdata('userid');
        $result    = $this->user_m->name_and_email($userid);
        $this->input->set_post('name', $result['name']);
        $this->input->set_post('email', $result['email']);
    }
}

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Input extends CI_Input
{
     function __construct()
     {
         parent::CI_Input();
     }

    // --------------------------------------------------------------------

    function set_post($field, $value)
    {
        $_POST[$field] = $value;
    }
}

You need to complement this using set_value() in your view. I mentioned that you should look into the manual for the Form helper functions. An example below:

Code:
<input type="text" name="email" value="<?=set_value('email')?>" />


Messages In This Thread
Would like to condense some code. - by El Forum - 09-29-2009, 10:29 AM
Would like to condense some code. - by El Forum - 10-01-2009, 08:53 AM
Would like to condense some code. - by El Forum - 10-02-2009, 10:16 AM
Would like to condense some code. - by El Forum - 10-08-2009, 05:50 AM
Would like to condense some code. - by El Forum - 10-08-2009, 06:10 AM
Would like to condense some code. - by El Forum - 10-08-2009, 07:01 AM
Would like to condense some code. - by El Forum - 10-08-2009, 08:30 AM
Would like to condense some code. - by El Forum - 10-09-2009, 06:42 AM
Would like to condense some code. - by El Forum - 10-09-2009, 09:35 AM
Would like to condense some code. - by El Forum - 10-09-2009, 12:27 PM
Would like to condense some code. - by El Forum - 10-09-2009, 01:19 PM
Would like to condense some code. - by El Forum - 10-09-2009, 02:51 PM
Would like to condense some code. - by El Forum - 10-09-2009, 05:41 PM
Would like to condense some code. - by El Forum - 10-09-2009, 05:44 PM
Would like to condense some code. - by El Forum - 10-11-2009, 12:37 PM
Would like to condense some code. - by El Forum - 10-11-2009, 12:47 PM
Would like to condense some code. - by El Forum - 10-11-2009, 02:58 PM
Would like to condense some code. - by El Forum - 10-13-2009, 08:31 AM
Would like to condense some code. - by El Forum - 10-14-2009, 10:02 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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