2014-02-17 86 views
1

我正在cakephp進行調查。這是我第一次使用cakephp,我偶然發現了一個問題,所以我需要一些建議。我想有多個答案選項(單選按鈕),最後只有一個提交按鈕。多個表單 - 一個提交按鈕

我正在FormHelper,我的問題:我必須在我的數據庫中輸入每個問題,然後用cakephp獲取它嗎?或者可以將它放在我的HTML中,只需在cakephp中添加答案選項即可。

這是我現在有(HTML +的CakePHP的單選按鈕)

Example

但是當我嘗試輸入多個答案選項+問題,我得到這個:

Example2

我的代碼:

<div class="question"> 

<div class="number"> 
      <p>1</p> 
</div> 

<div class="questionI"> 
      <p>The organization’s mission/purpose is absolutely clear</p> 
</div> 

<div class="answers"> 

      <?php 

      echo $this->Form->create(); 
      $options = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10'); 
      $attributes = array('legend' => false); 
      echo $this->Form->radio('answer1', $options, $attributes); 
      echo $this->Form->radio('answer2', $options, $attributes); 
      echo $this->Form->end('Submit'); 
      ?> 
</div> 

</div> 

我的第二個問題是另一個問題的div,所以我知道我無法使他們的方式.. 我想這樣做每個循環的,但後來我想我必須把每一個問題在我的數據庫?

回答

2

你應該在上面創建表單,在年底關閉它,有問題的表狀結構。 像:

<?php echo $this->Form->create(); 
     $options = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10'); 
     $attributes = array('legend' => false);?> 

<div class="question question-1"> 
    <div class="number">1</div> 
    <p class="questionI">The organization’s mission/purpose is absolutely clear</p> 
    <div class="answer"> 
     <?php echo $this->Form->radio('answer1', $options, $attributes);?> 
    </div> 
</div> 

<div class="question question-2"> 
    <div class="number">2</div> 
    <p class="questionI">The organization’s mission/purpose makes me feel that my job is important, and I’m proud to be part of this organization</p> 
    <div class="answer"> 
     <?php echo $this->Form->radio('answer2', $options, $attributes);?> 
    </div> 
</div> 

<?php echo $this->Form->end('Submit');?> 

你並不需要輸出的所有形式的零部件在同一個地方,只要它是在表單內

+0

謝謝!當你解釋它時似乎很簡單:D – Jnb