php - Codeigniter - Grab value from dropdown pass to controller -


i trying pass value form has 3 options when user clicks on of options should pass value controller.

i thinking maybe can have `onchange="selectedvalue". tried grab post view did not work.

any appreciated

view

            <label>reports</label>             <form>             <select name="hours">               <option value="24">24</option>               <option value="12">12</option>               <option value="1">1</option>              </select>             </form> 

controller

public function about() {     $search = $this->input->post('hours');      echo $search;      $this->load->view("about"); } 

you'd pass value view controller, sumitting form in view function in controller. can add javascript form automatically submit when option selected - onchange="this.form.submit()". (rather using button, example.)

view

<form method="post" accept-charset="utf-8" action="<?php echo site_url("yourcontroller/about"); ?>">     <select name="hours" onchange="this.form.submit()">         <option value="24">24</option>         <option value="12">12</option>         <option value="1">1</option>     </select> </form> 

controller

public function about() {     //get value form.     $search = $this->input->post('hours');      //put value in array pass view.      $view_data['search'] = $search;      //pass value view. access '$search' in view.     $this->load->view("about", $view_data); } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -