Passing variable for $_POST

Asked

Viewed 227 times

1

I got the following foreach()

    <? foreach($cidades as $valor){ ?>
    <div class="listacidade"><a href="<? echo base_url("cidade/".$valor->idParametro."-".url_title($valor->parametro)); ?>"><img src="<? echo base_url(); ?>site/modules/entrada/images/<?=url_title($valor->parametro);?>.jpg" width="250" height="120" alt=""/></a></div>
    <? } ?>

In it I already make the normal query of the database and display according to the list of cities, but I need to click on one of the cities, that I can pass the idParametro somehow, it may even be in $_POST or $_SESSION... I just wouldn’t want you to show up at the URL.

I thought of using city/codity-naming but it doesn’t work, because of the module, then I would have to create a module for each city.

Passing only the id would already be good.

1 answer

0

You can exchange this DIV for a select option, put it inside a form and in the value of the select, you put the Idparameter and send the data in the Ubmit with the post method. Is one of the solutions.

  • It wouldn’t work because I have a picture in this DIV and I would need it to appear...

  • Then you can take the idParametro of your DIV using Javascript or jQuery, and do a function that sends this data to your controller using AJAX. ;)

  • That’s right Bruno, but how would you do it?

  • Dude, you can put in the element that will receive the click(div, link or img) the tag html data-idparameter="35" and with jquery take the value 35, example: var idparametro = $('element selector'). attr('data-idparameter'). Then make the ajax request by passing the idparameter you took to the controller, example: $.ajax({ type: "POST", date: { id_parametro:idparametro }, url: "rota_da_function_da_sua_controller", dataType: "html" });

  • It worked @Andrébaill?

  • No, I was able to elaborate differently, using Session

  • Legal @Andrébaill

Show 2 more comments

Browser other questions tagged

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