如何在会话中传递表单字段值并在cakephp中显示div标签内部

时间:2016-12-02 10:21:49

标签: cakephp

提前致谢,其实我的表格上有考试名称,地点,考试日期,价格/课程,考试次数和添加到购物车提交按钮,下面我有<div id="division"></div>。在表单字段中输入详细信息并提交表单后,表单字段值应传递到下面的<div id="division"></div>标记。对于表单的每个条目,值应添加到<div id="division"></div>标记。我想删除我之前添加的项目。如何使用cakephp中的session进行此操作。比如在购物车中将商品添加到购物车中。

My index.ctp view page
   <table><thead>
          <th>Exam Name</th>
          <th>Venue Name</th>
          <th>Date of Exam</th>
          <!--<th>Documents</th> --> 
          <th>Price / Course</th>  
          <th>Number of Exams</th>
          <th style="display:none">Document</th>  
          <th>Add to Cart</th> 
         </thead>
         <tbody>
          <tr>
    <form name="cartTable" id="cartTable" method="post" action="<?php echo $this->webroot ?>users/cartData/?>">  
             <td><?php echo $k; ?></td> 
              <td id="examCart">
              <span id="errname"></span>
              <select name="course" id="course" required="required">  
                <option value="">--Select--</option>
                <!--<option>Prince 2 Foundation</option>
                <option>Prince 2 Practitioner</option>
                <option>ITIL Foundation</option> 
                <option>COBIT Foundation</option> -->
                <?php foreach($userexams as $userexam):
                    $cmbExams = $userexam['exams']['exam'];      
                    $newtest = explode(',',$cmbExams);                
                    for($i=0;$i<count($newtest);$i++) 
                    {
                    ?>
                 <option value="<?php echo $newtest[$i];?>"><?php echo $newtest[$i];?></option>
                <?php 
                    }
                   endforeach; ?>

              </select>           
              </td>    
              <td id="examvenue"><span id="errVenue"></span><input type="text" name="venue" id="venue" required="required"></td>        
          <td><span id="errDate"></span><input type="text" name="Userdate" id="Userdate" required="required"></td>
           <!--<td><?php //echo $alldata['e']['document']; ?></td>-->
           <td id="priceCart"><?php echo "$0"; //echo "$0 ".$alldata['e']['price']; ?></td> 

           <td>
              <span id="errNoExam"></span>
              <select required="required" class="create-user" name="data[Exam][orderexam]" id="orderCart" onchange="change()">
               <option value="">-- Select --</option>                      
              <?php
                 for($i=1;$i<=10000;$i++)  
                 {
              ?> 
              <option value="<?php echo $i; ?>"><?php echo $i; ?></option>                    
             <?php } ?>          

           </td>
           <td style="display:none"><input type="text" name="hide" value="<?php echo $alldata['e']['document']?>"></td>
           <td><input type="submit" name="btnAddCart" value="Add to Cart" class="cartbtn"><!--<button type="button" class="btn btn-success btn-xs cartbtn">Add to Cart</button>--></td> 
           </form>
         </tr></tbody>
    <div class="container cartdetails"> 
       <div class="row"> 
        <div class="col-md-10">
         <p style="font-size:25px;text-align:center;">Cart Details</p> 

           <div id="division">

       ////// I Have to pass the session values here ///////    

           </div>
        <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 
          <input type="hidden" name="cmd" value="_cart">
          <input type="hidden" name="business" value="ragith.thomas@yahoo.com"> 
          <input type="hidden" name="upload" value="1">

            <input type="hidden" name="item_number_" value="" id="itm_no">    
            <input type="hidden" name="item_name_" value="" id="item_name">   
            <input type="hidden" name="amount_" value="" id="eprice"> 
            <input type="hidden" name="shipping_" value="sdssddd" >  
            <input type="hidden" name="quantity_" value="3" id="eorder"> 

          <input type="hidden" name="currency_code" value="USD" >     

          <input type="hidden" name="amount" value="" id="payTotal">  

          <!--<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" id="placeOrder"> -->
        </form>
    </div>
    </div>
    </div>

    My UsersController.php page code as below

    <?php
    App::uses('CakeEmail', 'Network/Email');
    class UsersController extends AppController
    {

       public function cartData() 
       {



        }

    }

1 个答案:

答案 0 :(得分:2)

你的问题非常广泛,代码看起来并不像CakePHP。在CakePHP中,您应该使用Form Helper来构建表单(http://book.cakephp.org/3.0/en/views/helpers/form.html)并发布数据,然后在控制器操作中处理该数据并使用会话对象来存储数据(http://book.cakephp.org/3.0/en/development/sessions.html#accessing-the-session-object