Capturing values from a Select to the Controller - Codeigniter

Asked

Viewed 150 times

0

Good morning Galerinha, everything beautiful?

I’m starting with the codeigniter and in the middle of that process I came across a question about the function select. Well, my question is to return the value from that select to mine controller, so I can do a check from the value. I have a chart and I need to control his information by mine select. As if my select become a button, then when I chose the option automatically the chart information would change.

select{

    -webkit-appearance: none !important;
    -webkit-border-radius: 0px;
    background-color: #fafafa;
    
    background-position: 100% center;
    background-repeat: no-repeat;
    border: 1px solid #cccccc;
    padding: 0.5rem;
    font-size: 0.875rem;
    color: rgba(0, 0, 0, 0.75);
    line-height: normal;
    border-radius: 0;
    height: 2.3125rem; 
    border-radius: 1px rgb(189, 189, 189) !important;
    min-width: 20px !important;
    
    
    
}
<select class="form-control" id="menuselect">
                     <option>Only me</option>
                     <option>Team</option>
                  </select>

1 answer

0


<select class="form-control" id="menuselect">
                 <option value="1">Only me</option>
                 <option value="2">Team</option>
              </select>

just put the value of each option, and when relating this value in the controller just take the id of the select, in which case it is id="menuselect"

value tbm can receive some controller id...

  • Okay, only that’s my question, how do I get it in the controller? $this->input->post() ? or set_select()?

  • look php is not my specialty but tries the following command, $selectOption = $_POST['menuselect'];

  • I’m by the codeigniter, I made the call, but it doesn’t work, I think I should turn my select into a "button" like the form action.

  • I gave a search to have help here, people say to use this command $variavel = $this->input->post("menuselect");, in case you need to make sure that the select is inside a form with http method being post

  • I did it here, but my value isn’t being captured. was like this Html: <form name="selectUser" id="selectUser" method="post" action="Welcome/client"> <select class="form-control" onchange="Document.getElementById('selectUser'). Submit()" > <option value='<? php$_SESSION["name"]? >'>Only me</option> <option value="Diego">Team</option> </select> </form> my controller insert like this: $name = $this->input_post('selectUser'); echo $name; .

  • Got it! I forgot to declare name="selectUser" in my <select>! Thanks for helping!

  • I believe you are not taking it because you did not give a reference id to select, what should be coming to the controller is an empty request, try to put a name in select and give a name to it and in the controller try to capture the name of select not the id, name of the form, just for tbm, make a simple test, in onchange put an Alert and pass the value of select to see what it returns

  • perfect! I’m happy to help

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.