Welcome Guest, Not a member yet? Register   Sign In
get selected text and selected value from select box in controller ?
#1

(This post was last modified: 10-06-2019, 10:12 PM by rencya6.)

[eluser]thaodth[/eluser]
I have a form. I want get value selected and text selected from select box, but $this->inpust->post() only get value, I want get text selected, too.
Code HTML:
Code:
Code:
<form id="frmAddHostInfo" class="validate" method="post" action="<?php echo $base_url?>dashboard/insert_new_host">
        <div class="content no-padding">
         <div class="section _100">
          <label>
           Host name
          </label>
          <div class="_100">
           &lt;input class="required" name="hostname" id="hostname"&gt;
          </div>
         </div>
         <div class="section _100">
          <span class="label">In group</span>
          <div class="_100">
           <p>
            <select id="group" name="group" class="required"> &lt;!-- class "required" used in jquery.validate.js --&gt;
             <option></option>
             &lt;?php foreach($groups as $groupid=>$grpname) { ?&gt;
              <option value="&lt;?php echo $groupid; ?&gt;">&lt;?php echo $grpname;?&gt;</option>
             &lt;?php } ?&gt;
            </select>
           </p>
          </div>
         </div>
</div>
&lt;/form&gt;


Code in controller:
Code:
Code:
public function insert_new_host()
{
  //$hostname, $os, $ip, $groupid, $groupname, $pid, $pname, $departmentid, $dname
  $hostname = $this->input->post('hostname');
// $groupid = ?? //how to get?
//$groupname = ??? //how to get?
        }


Please show me how to solve this problem!

Xem https://chuyennha.suu.vn/dich-vu-chuyen-nha.html
Reply
#2

(This post was last modified: 03-23-2016, 09:33 AM by Wouter60.)

You already have an array called $groups.
The <select> element returns the value of the selected item.

PHP Code:
$groupid $this->input->post('group');
$groupname $groups[$groupid]; 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB