dongyouzhi7218 2017-10-17 07:07
浏览 26
已采纳

PHP,CODEIGNITER如何从隐藏视图的控制器添加

I have problem that my input "type" is never post in database because I don't give input type in the view (I want value of my type is set by controller/hidden)... and this is my code

Controller :

<?php
    public function addSmsCampaign() {
    if (isset($_POST['addSmsCampaign'])) {
        $this->form_validation->set_rules('campaign_name', 'campaign name', 'required|is_unique[campaigns.campaign_name]');
        $this->form_validation->set_rules('sequence_qty', 'sequence quantity', 'required|integer');
        $this->form_validation->set_rules('label_id', 'label id', 'required');
        $this->form_validation->set_rules('type', '', 'required');

    //if form validation true
        if ($this->form_validation->run() == TRUE) {
            $sms = 1;

            $newcampaign = [
                'campaign_name' => $_POST['campaign_name'],
                'sequence_qty' => $_POST['sequence_qty'],
                'label_id' => $_POST['label_id'],
                'type' => $this->input->post('type'),
                'created_at' => date('Y-m-d')
            ];
            $this->db->insert('campaigns', $newcampaign);
            redirect('userCont/sequenceform', 'refresh');
        }
    }
?>

and this is my view:

<form action="" method="POST">
    <div class="form-group">    
        <label for="campaign_name">Input Campaign Title </label>
        <input type="text" class="form-control" name="campaign_name" id="name">
    </div>

    <div class="form-group">
        <label for="sequence_qty">Sequence qty </label>
        <input type="text" class="form-control" name="sequence_qty" id="qty">
        <input type="hidden" class="form-control" name="type" value="1">
    </div>

    <div class="form-group">
        <label for="label_id">Choose Category</label>

        <select class="form-control"  name="label_id" id="label_id">
            <?php
            foreach ($label_content as $e) {
                echo "<option value='$e->id;'>" . $e->label_name . "</option>";
            }
            ?>
        </select>
    </div>

    <div class="text-right">
        <button class="btn btn-primary form-control" value="1" name="addSmsCampaign type">next</button>
    </div><hr>
</form>

every time I post value of type is default = 0, and I want set value to 1... thanks a lot

  • 写回答

1条回答 默认 最新

  • douchui7332 2017-10-17 07:31
    关注

    try changing name from 'type' to some other name in db, controller and view

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 workstation加载centos进入emergency模式,查看日志报警如图,怎样解决呢?
  • ¥50 如何用单纯形法寻优不能精准找不到给定的参数,并联机构误差识别,给定误差有7个?matlab
  • ¥15 workstation加载centos进入emergency模式,查看日志报警如图,没有XFS,怎样解决呢?
  • ¥15 应用商店如何检测在架应用内容是否违规?
  • ¥15 Ubuntu系统配置PX4
  • ¥50 nw.js调用activex
  • ¥15 数据库获取信息反馈出错,直接查询了ref字段并且还使用了User文档的_id而不是自己的
  • ¥15 将安全信息用到以下对象时发生以下错误:c:dumpstack.log.tmp 另一个程序正在使用此文件,因此无法访问
  • ¥15 速度位置规划实现精确定位的问题
  • ¥15 MAC虚拟机(win11)USB插上后无串口com,无法烧录