Reputation: 89
I'm making a survey in cakephp. This is my first time using cakephp and I've stumbled upon a problem so I need some advice. I want to have multiple answersoptions (the radiobuttons) and only one submit button at the end.
I'm making a form with the FormHelper, my question: do I have to input each question in my database and then fetch it with cakephp? Or is it ok to put it in my HTML and just add the answer options with cakephp.
This is what I have now (HTML + cakephp for the radiobuttons)
But when I try to input multiple answer options + questions I get this:
My code:
<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>
My second question is in another question div so I know I can't align them that way.. I was thinking of doing a for each loop but then I suppose I have to put each question in my database?
Upvotes: 1
Views: 205
Reputation: 1595
You should create the form at top, close it at the end, and have a table-like structure for questions. Like:
<?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');?>
You don't need to output all form parts on the same place, as long as it's inside the form
Upvotes: 2