Pass value from a select to GET parameter of a link

0

Hello, I needed to pass the value from one to a parameter of a link, this to be sent via GET. I'm using the codeigniter framework.

Here's the code snippet I have:

<div class="col-xs-12 col-md-3 form-num-sala">
    <div class="row">
        <div class="col-xs-12 col-md-8" style="margin-left:-55px;">
            <div class="form-group">
                <label>Designação da sala</label>
                <br/>
                <select name="designacaoSala" class="form-control">
                    <?php foreach ($designacaoSala as $numsala) { ?>
                        <option value="<?php echo $numsala->numerosala ?>">
                            <?php echo $numsala->numerosala ?>
                        </option>
                        <?php } ?>
                </select>
            </div>
        </div>
        <div class="col-xs-12 col-md-4" style="margin-left:-25px;">
            <label>Aplicar</label>
            <br/>
            <a href="<?php echo site_url('utilizador/addSalaEspacoEvento/?idplano='.$hDefenidos->idplanoespacoevento.'&numerosala='); ?>">
                <button class="form-control"><i class="fa fa-check"></i></button>
            </a>
        </div>
    </div>

</div>

The variable $hDefenidos->idplanoespacoevento comes from above but the variable & numerosala should come from select with the name "designacaosala" and be assigned to the following link:

<a href="<?php echo site_url('utilizador/addSalaEspacoEvento/?idplano='.$hDefenidos->idplanoespacoevento.'&numerosala='); ?>">
    <button class="form-control"><i class="fa fa-check"></i></button>
</a>

Can anyone give a force? Thank you

    
asked by anonymous 05.05.2016 / 12:24

2 answers

0

If there is no problem in passing POST and not GET, you can do this: Instead of passing the variables on a link, you pass the values in form . When using the url in the codeigniter one can get the values by the segments (each "/" separates a segment, where the first comes just after the base url of the site). Example: www.site.com/segment1/segment2/segment3/ ... where segment1 is the name of the controller, segment2 the controller method name and segment3 a parameter to the method. The value of the select you get via POST.

VIEW : (I'll only use the functional part disregarding the formatting div's)

<form method="POST" action="<?=site_url('utilizador/addSalaEspacoEvento/'.$hDefenidos->idplanoespacoevento); ?>">
    <select name="designacaoSala" class="form-control">
        <?php foreach ($designacaoSala as $numsala) { ?>
            <option value="<?php echo $numsala->numerosala ?>">
                <?php echo $numsala->numerosala ?>
            </option>
            <?php } ?>
    </select>
    <input type="submit" value="Aplicar" />
</form>

CODEIGNITER CONTROLLER :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Utilizador extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function addSalaEspacoEvento($idplanoespacoevento) {
        $valorDoSelect = $this->input->post('designacaoSala');

        ...
    }
}

If you are using codeigniter routes, I suggest you review them if you have trouble finding the method on the request. Remember that the lib session must be loaded, either in the controller or in the autoload file.

I hope I have helped. :)

    
07.05.2016 / 00:58
0

Hello, from what I understand you want to pass the option value of the selected room to the link URL, right? I made a solution in jquery. The logic would be to get the link displayed by PHP, pick up the selected room and assign it on the link when another option is selected. Note: I omitted PHP codes. I added a class to the select and an id to the link tag, to select them with jquery. Link to the code: ( link )

    
15.12.2018 / 11:30