首页 文章

Codeigniter将表单值作为url段传递

提问于
浏览
1

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

这是我的观点:

<?= form_open('admin_gallery_upload/upload_images/'); ?>
<?= form_label('Gallerij', 'gallery_id'); ?>
<?= 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 ,而应该成为第三个url段

2 回答

  • 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

    您可以默认传入表单打开函数额外参数,如下所示: -

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

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

    $this->input->get();
    

相关问题