在codeigniter中提供客户反馈

时间:2018-06-29 17:09:40

标签: php html codeigniter

我需要收集有关所提供服务的反馈。

我认为我有以下内容:

 <form method="post" enctype="multipart/form-data" class="form-horizontal" id="entryForm">
  <div class="panel-body text-center">
   <ul class="list-group list-group-flush text-center">
    <li class="list-group-item">
     <input type="button" name="feedback" value="1" class="btn btn-info">
     <input type="button" name="feedback" value="2" class="btn btn-info">
     <input type="button" name="feedback" value="3" class="btn btn-info">
     <input type="button" name="feedback" value="4" class="btn btn-info">
     <input type="button" name="feedback" value="5" class="btn btn-info">
    </li>
   </ul>
  </div>
 </form>

 <div class="panel-footer text-center">
  <button type="button" id="submit" class="btn btn-primary btn-lg btn-block">
   Submit
  </button>

在我的控制器中,我有以下内容:

    public function index(){
        $feedback = $this->input->post('feedback');
        $this->Feedback_model->addFeedback($feedback);
        $this->load->view('feedback/header');
        $this->load->view('feedback/survey');
        $this->load->view('feedback/footer');
    }

在我的模型中,我有以下内容:

  public function addFeedback($feedbackData){
    var_dump($feedbackData);
  }

我有一个js文件,可响应按钮单击:

$(document).ready(function(){

 $("#submit").click(function(e){
     e.preventDefault();
     $("#entryForm").submit();
 });

});

我只想获取按钮的值。

1 个答案:

答案 0 :(得分:0)

希望这对您有帮助:

1。更改按钮类型以提交并为其指定名称和值:

<div class="panel-footer text-center">
   <button type="submit" name='action' value="submit" id="submit" class="btn btn-primary btn-lg btn-block">
   Submit
  </button>
</div>

2。您的提交按钮应位于form标记内

3。对于反馈表,您的按钮类型应为radiocheckbox,默认情况下,其中一个应为checked

整个表单应如下所示:

表单操作应具有类似action="<?=site_url('welcome/index');?>"这样的URL,其中welcome是您的控制器名称 如果欢迎不是您的控制者,请更改它:

<form action="<?=site_url('welcome/index');?>" method="post" enctype="multipart/form-data" class="form-horizontal" id="entryForm">
  <div class="panel-body text-center">
   <ul class="list-group list-group-flush text-center">
    <li class="list-group-item">
     <input type="radio" name="feedback" value="1" class="btn btn-info" checked>
     <input type="radio" name="feedback" value="2" class="btn btn-info">
     <input type="radio" name="feedback" value="3" class="btn btn-info">
     <input type="radio" name="feedback" value="4" class="btn btn-info">
     <input type="radio" name="feedback" value="5" class="btn btn-info">
    </li>
   </ul>
  </div>

 <div class="panel-footer text-center">
  <button type="submit" id="submit" name="action" value="submit" class="btn btn-primary btn-lg btn-block">
   Submit
  </button>
 </div>
   </form>

您的控制器的index应该是这样的:

public function index()
{
    if($this->input->post('action') === 'submit')
    {
        $feedback = $this->input->post('feedback');
        echo $feedback;
        die;
        $feedback = $this->input->post('feedback');
        $this->Feedback_model->addFeedback($feedback);
    }

    $this->load->view('feedback/header');
    $this->load->view('feedback/survey');
    $this->load->view('feedback/footer');
}