Codeigniter将表单值作为url段传递

时间:2013-07-25 07:49:03

标签: codeigniter url

我有codeigniter的问题。我想在下一页中将表单值(从下拉列表)传递为URL段。然而,我搜索了高低,但找不到解决方案。

以下是我的观点:

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

我的控制器:

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

因此,它不应像控制器中那样回显$gallery_id,而应该成为第三个网址段

2 个答案:

答案 0 :(得分:1)

尝试此操作并将选择框ID设为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;
} 

更改以下行,按照我的说法添加下拉列表的ID,

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

答案 1 :(得分:1)

您可以默认传递表单open function extra参数,如下所示: -

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

使用以下方法获取控制器: -

$this->input->get();