2014-02-17 89 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