Is it possible for to display in a column instead of side by each?
The Radio options are selected in FormElement
namespace Main\Form\Element;
use Doctrine\ORM\EntityManager;
use Zend\Form\Element\Radio;
/**
* Class SurveyAnswerRadio
*
* @package Main\Form\Element
*/
class SurveyAnswerRadio extends Radio
{
/**
* @var EntityManager $entityManager
*/
protected $entityManager;
/**
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* Get Value Options
*
* @return array
*
* @throws \Exception
*/
public function getValueOptions()
{
$array = [];
$survey_question_reference = 1;
$result = $this->entityManager
->getRepository('AMDatabase\Entity\TheVerse\SA')
->findBy(
[
'sqReference' => $survey_question_reference
],
[
'surveyAnswer' => 'ASC'
]
);
if (is_array($result) && count($result) > '0') {
/**
* @var \AMDatabase\Entity\TheVerse\SA $val
*/
foreach ($result as $val) {
$array[$val->getReference()] = $val->getSurveyAnswer();
}
}
return $array;
}
}
This is added to the Form
/**
* Survey Answer
*/
$this->add(
[
'type' => 'Main\Form\Element\SurveyAnswerRadio',
'name' => 'survey_answer',
'options' => [
'label' => 'survey_answer'
],
'attributes' => [
'id' => 'survey_answer'
]
]
);
}
Then it is displayed within a view Twig
<div class="field">
<span>{{ formLabel(form.get('survey_answer')) }}</span>
{{ formRadio(form.get('survey_answer')) }}
</div>
The output encloses each within a . I am wanting the output to be displayed in this fashion:
<ul>
<li><label><input type="radio" name="survey_answer" id="survey_answer" value="1">option 1</label><li>
<li><label><input type="radio" name="survey_answer" id="survey_answer" value="2">option 2</label></li>
<li><label><input type="radio" name="survey_answer" id="survey_answer" value="3">option 3</label></li>
</ul>
use this command in view
$this->formRadio()->setSeparator('</li><li class="yourclass">');
this command set separator between your radio options.
then you show your element like this
<li class="yourclass" >
<?php echo $this->formRadio($form->get('survey_answer')); ?>
</li>