1

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

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

5 Comments

That does not appear to do anything
I already added that, as you requested, but that did not work
ReferenceError: $ is not defined
I am no longer receiving any errors, but for some reason nothing happens either
Correction; it does! Thanks :)
1

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();

2 Comments

Is there no direct way of passing the gallery_id? Since I have no idea how to only pass the id instead of all form information
Then You have to pass in to simple javascript function galler_id and redirect it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.