user2599060
user2599060

Reputation: 37

Codeigniter pass form value as url segment

I have an issue with codeigniter. I want to pass a form value (from a dropdown) as URL segment in the next page. However I have searched high and low but could not find the solution.

Here is my view:

<?= form_open('admin_gallery_upload/upload_images/'); ?>
<?= form_label('Gallerij', 'gallery_id'); ?><br/>           
<?= form_dropdown('gallery_id', $select_dropdown); ?>
<?= form_submit('submit', 'Volgende',  'class="submit"'); ?>
<?= form_close(); ?>

My controller:

function upload_images() {
   $gallery_id = $this->input->post("gallery_id");
   echo $gallery_id;        
}

So instead of echoing the $gallery_id as done in the controller, it should become the third url segment

Upvotes: 1

Views: 2678

Answers (2)

Nil&#39;z
Nil&#39;z

Reputation: 7475

Try this and put select box id as gallery_id:

function redirectFunction(){
    var val  = document.getElementById("gallery_id").value;
    alert(val); //see if alerts the correct value that is selected from the dropdown
    window.location.href = '<?php echo base_url()?>admin_gallery_upload/upload_images/'+val;
} 

Change the following lines, to add the id of the dropdown as I said,

$js = 'id="gallery_id" onChange="redirectFunction();"';
form_dropdown('gallery_id', $select_dropdown,'',$js);

Upvotes: 1

Prasannjit
Prasannjit

Reputation: 795

You can pass in form open function extra parameter by default it is post see below code :-

<? $arr = array('method'=> 'GET');?>
<?= form_open('admin_gallery_upload/upload_images/',$arr); ?>

And get on controller using :-

$this->input->get();

Upvotes: 1

Related Questions