Welcome Guest, Not a member yet? Register   Sign In
How to get additional data ' id' from <select> options
#1

[eluser]Jan_1[/eluser]
Hello! As I've read in the User Guide:
Quote:If you would like the opening <select> to contain additional data, like an id attribute, you can pass it as a string in the fourth parameter:
$js = 'id="shirts" onChange="some_function();"';

echo form_dropdown('shirts', $options, 'large', $js);


So I did, but I dont know how to grab the 'additional data' to write it in the database.
Could somebody give me hint or a link to a post (which I haven't found).
THANK YOU!!!

View
Code:
&lt;?php echo form_open_multipart('kasse/save_ks_buchung'); ?&gt;
    <tr>
      <td>&lt;input type='text' name='ks_datum' value="&lt;?php echo mdate($datestring, $time); ?&gt;" size='12'/&gt;&lt;/td>
      <td>&lt;input type='text' name='ks_text' value="" size='30'/&gt;&lt;/td>
      <td>&lt;input type='text' name='ks_betrag' value="" size='8'/&gt;&lt;/td>
      <td>&lt;?php echo form_dropdown('ks_art', $options_ks_art, 'Sonstiges');?&gt;</td>
/*->*/<td>&lt;?php echo form_dropdown('ks_auslage',$name_ks_auslage,$selected_ks_auslage,$id_ks_auslage);?&gt;</td>
      <td>&lt;input type='hidden' name='wg_id' value='&lt;?=$wg[0]-&gt;wg_id?&gt;'/>
          &lt;input type='submit' value='speichern'/&gt;&lt;/td>
    </tr>
  &lt;/form&gt;

Controller:
Code:
function show()
    {
        $this->load->helper('date');
        $this->load->helper('form');
        $this->load->model('kasse/kasse_model');
        $this->load->model('standard_model');
        $data['wg']= $this->standard_model->get_wg_id();
        $data['options_ks_art'] = $this->kasse_model->get_ks_art();
        $data['name_ks_auslage'] = $this->kasse_model->get_ks_auslage_name();
        $data['selected_ks_auslage'] = $this->kasse_model->get_ks_auslage_wg();
        $data['id_ks_auslage'] = $this->kasse_model->get_ks_auslage_id();
        $data['ks_buchungen'] = $this->kasse_model->get_my_ks_buchungen();
        
        $dataform['heading'] = 'Unsere WG-Kasse';
        $dataform['page'] = $this->config->item('FAL_template_dir').'template/kasse/meine_kasse_temp';

        $this->load->vars($data);
        $this->load->view($this->_container, $dataform);
    }

    function save_ks_buchung()
    {
        $this->load->model('kasse/kasse_model');
        $this->load->helper('form');
        $this->load->plugin('js_calendar');
        $this->kasse_model->insert_ks_buchung();
        redirect('/kasse/show', 'refresh');
  }

Model:
Code:
function get_ks_auslage_name()
    {
      $wg_id = x; // done by db-query, if've just cut it here (works)  
      $data = array();
      $this->db->select('user_name');
      $this->db->where('wg_id',$wg_id, FALSE);
      $this->db->where_not_in('user_id', $this->db_session->userdata('id'), False);
      $query = $this->db->get('wg_member');
          foreach ($query->result() as $row)
                  {$data[$row->user_name] = $row->user_name; }
      return $data;
     }

  function get_ks_auslage_id()
    {
      $wg_id = x; // done by db-query, if've just cut it here (works)
      $data = array();
      $this->db->select('id');
      $this->db->where('wg_id',$wg_id, FALSE);
      $this->db->where_not_in('user_id', $this->db_session->userdata('id'), False);
      $query = $this->db->get('wg_member');
          foreach ($query->result() as $row)
                  {$data[$row->id] = $row->id;}
      return $data;
     }
    
  function get_ks_auslage_wg()
    {
      $wg_id = x; // done by db-query, if've just cut it here (works)
      $data = array();
      $this->db->select('user_name');
      $this->db->where('wg_id',$wg_id, FALSE);
      $this->db->like('user_name','WG', FALSE);
      $query = $this->db->get('wg_member');
          foreach ($query->result() as $row)
                  {$data[$row->user_name] = $row->user_name;}
      return $data;
     }

  function insert_ks_buchung()
    {
      extract($_POST);
      $data = array(
                    'geloescht' => '0',
                    'wg_id' => $wg_id,
                    'user_name' => getUserName(),
                    'user_id' => $this->db_session->userdata('id'),
                    'ks_datum' => $ks_datum,
                    'ks_text' => $ks_text,
                    'ks_betrag' => $ks_betrag,
                    'ks_art' => $ks_art,
                    'change_user' => '0',
                    'ks_auslage' => $ks_auslage,
                    'id_ks_auslage' => $id_ks_auslage  // how could I pass it down here from the VIEW??
                   );
      $this->db->insert('ks_buchung', $data);
    }
#2

[eluser]TheFuzzy0ne[/eluser]
You can't. Only the name and value is sent. If your code dynamically adds the IDs, it's safe to say that they should have some kind of record of them, so you should be able to associate these IDs with the name/values of the select input.




Theme © iAndrew 2016 - Forum software by © MyBB