I am creating a form where the person will need to answer a questionnaire with some questions, knowing that they will all be of the radio type, being able to select only one answer from those listed (standardized answers). The problem is that when I send the form, all the values are coming up empty.
Front
<?php $option = 0; ?>
<?php foreach ($quiz_questions as $quiz) : ?>
<div class="row">
<?php foreach (ResponsesDefaultENUM::findConstants() as $key => $response) : ?>
<div class="col-md-<?= $key === ResponsesDefaultENUM::DISCORDO_CONCORDO ? '3' : '2'; ?>">
<?= $this->Form->control('responses[' . $option . '][id]', ['type' => 'radio', 'options' => [$key => $response], 'label' => false]); ?>
</div>
<?php endforeach; ?>
<?php $option++; ?>
</div>
<?php endforeach; ?>
How the input is being generated
<input type="hidden" name="responses[0][id]" value="" />
<div class="radio">
<label for="responses-0-id-1">
<input type="radio" name="responses[0][id]" value="1" id="responses-0-id-1"/>Test</label>
Standardized answers
class ResponsesDefaultENUM {
const COMPLETELY_DISAGREE = 1;
const DISAGREE = 2;
const DISAGREE_AGREE = 3;
const AGREE = 4;
const COMPLETELY_AGREE = 5;
public static function findConstants($value = NULL) {
$values = array(
self::COMPLETELY_DISAGREE => "Completely disagree",
self::DISAGREE => "Disagree",
self::DISAGREE_AGREE => "I neither agree nor disagree",
self::AGREE => "I agree",
self::COMPLETELY_AGREE => "I totally agree"
);
if ($value != NULL) {
if (is_numeric($value))
return isset($values[$value]) ? $values[$value] : NULL;
else
return array_search($value, $values);
} else {
foreach ($values as $id => $cVal) {
$ret[$id] = $cVal;
}
return $ret;
}
}
}
The return is as follows:
[
'responses' => [
(int) 0 => [
'id' => ''
],
(int) 1 => [
'id' => ''
],
(int) 2 => [
'id' => ''
]
]
]
The values above are arriving empty.
What I need is to make the correction so that they are filled out.