我正在使用cakephp进行调查。这是我第一次使用cakephp,我偶然发现了一个问题,所以我需要一些建议。我希望有多个answersoptions(radiobuttons),最后只有一个提交按钮。
我正在使用FormHelper创建一个表单,我的问题是:我是否必须在我的数据库中输入每个问题然后用cakephp获取它?或者可以将它放在我的HTML中,只需添加cakephp的答案选项即可。
这就是我现在所拥有的(无线电按钮的HTML + cakephp)
但是当我尝试输入多个答案选项+问题时,我得到了这个:
我的代码:
<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,所以我知道我不能那样对齐它们.. 我想为每个循环做一个但是我想我必须把每个问题放在我的数据库中?
答案 0 :(得分: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');?>
您不需要在同一个地方输出所有表单部分,只要它在表单中