如何确保点击哪个星形按钮

时间:2016-04-06 14:46:18

标签: javascript php codeigniter

我正在使用codeigniter,我有一个表格,我可以评价产品。他们实施了星形按钮。每当我点击一个按钮时,在标签中它会显示“可怕的”文本,依此类推。我需要知道的是,每当我提交表格时,我需要确保用户点击任何星形按钮并给出他/她的费率。这意味着需要提供费率。我怎样才能做到这一点。我认为这个。但它始终显示“您没有提供评级”错误消息。

businessRateView.php

<?php $Vehicleid=$details['id']; ?>
                        <form action="<?php echo 'http://localhost/ci/businessRateCtrl/insertIntoBusinessReview/'.$Vehicleid?> " method="POST">

                        <h2>Rate Ad</h2>
                        <p>All field marked with * are required</p>
                        <div style="color:red">
                    <?php
                        $CI =& get_instance();
                        $CI->load->library('form_validation');
                        echo validation_errors();
                    ?>
                    </div>

                         <div class="spacer-20"></div>
                        <h4>Your rating*</h4>


                        <h1><div class="rating" style="width:200px;float:left;padding-left:1px">
                            <span class="rate-star" data-rate="Excellent">&bigstar;</span> 
                            <span class="rate-star" data-rate="Good" >&bigstar;</span> 
                            <span class="rate-star" data-rate="Okay" >&bigstar;</span>
                            <span class="rate-star" data-rate="Unsatisfied" >&bigstar;</span>
                            <span class="rate-star" data-rate="Terrible" >&bigstar;</span>
                            </div>
                        </h1>

                        <div style="float:right;padding-right:450px">
                        <h3><label id="rateText" name="lblrating"></label></h3>
                        </div>


                        <div class="spacer-20"></div>



                         <h4>Write your review</h4>
                          <div class="spacer-20"></div>
                        <label class="col-md-4"> Title </label> 
                        <input type="text" name="reviewTitle" placeholder="Title your review" class="form-control">     

                        <div class="spacer-20"></div>

                        <label class="col-md-4">Your review </label>       
                        <textarea rows="10" cols="103" name="review" placeholder="Write your review" class="form-control"></textarea>
                        <div class="spacer-20"></div>
                       <a class="btn btn-primary btn-lg" href=<?php echo 'http://localhost/ci/adpreview_ctrl/getad_preview/'.$Vehicleid?>  onclick="return cancelConfirm();">Cancel</a>

                        <input type="submit" name="submitreview" class="btn btn-primary btn-lg" value="SUBMIT">

                        </form>

businessRateCtrl.php

     public function loadReviewPage($vehicleid){


        $data=array();
        $data['details']['id']=$vehicleid;

        $this->load->view('pages/templates/header');
            $this->load->view('pages/businessRateView',$data);
            $this->load->view('pages/templates/footer');



    }

    public function insertIntoBusinessReview($Vehicleid){

          $data=array();
        $data['details']['id']=$Vehicleid;

         $this->form_validation->set_rules
            (
                'lblrating',
                'lblrating', 
                'required',
                array
                (
                    'required'      => 'You have not provided Rating',

                )
            );


              if ($this->form_validation->run() == FALSE)
            {
              $this->load->view('pages/templates/header');
                $this->load->view('pages/businessRateView',$data);
                $this->load->view('pages/templates/footer');

            }

            else{
              $this->main_model->insertIntoBusinessReview($Vehicleid);
          //$_SESSION['ads']=$_SESSION['ads']+1;
          $this->session->set_flashdata('success_msg', 'Thank you! We will post your review soon');
          redirect("<?php echo 'http://localhost/ci/adpreview_ctrl/getad_preview/'.'$Vehicleid' ?>");

        }

mainmodel.php

    public function insertIntoBusinessReview($Vehicleid){

                $rating = $_POST['lblrating'];

                if(($_POST['reviewTitle'])!==null || ($_POST['review'])!==null)
                {
                $title=$_POST['reviewTitle'];
                $review=$_POST['review'];

                $data=array('Vehicleid'=>$Vehicleid,'rating'=>$rating,'title'=>$title,'review'=> $review,'reviewPoster'=>$this->session->userdata['logged_in']['email']);
                $this->db->insert('businessreviews',$data);
                }

                $data=array('Vehicleid'=>$Vehicleid,'rating'=>$rating,'reviewPoster'=>$this->session->userdata['logged_in']['email']);
                $this->db->insert('businessreviews',$data);


            }



Please help me.

0 个答案:

没有答案