У меня есть форма, которая имеет несколько разделов, каждый раздел имеет несколько шагов. Каждый шаг имеет минимум один флажок, максимум два и может содержать текстовую область комментариев.
Я загружаю всю форму (вопросы) из БД, и я создал цикл для этого. Я также называю поле ввода «имя» значением при прохождении через цикл следующим образом:
<input type="checkbox" name="section_<?php echo $section_id; ?>[<?php echo $step_numb; ?>][anso]" id="anso-check-<?php echo str_replace(".","-",$section_id)."-" .$step_numb; ?>" required="required">
<input type="checkbox" name="section_<?php echo $section_id; ?>[<?php echo $step_numb; ?>][anst]" id="anst-check-<?php echo str_replace(".","-",$section_id)."-" .$step_numb; ?>" required="required">
<textarea onkeyup="textAreaAdjust(this)" name="section_<?php echo $section_id; ?>[<?php echo $step_numb; ?>][com]"></textarea>
Так что в основном это будет выглядеть так:
<input type="checkbox" name="section_5[1][anso]" id="anso-check-5-1" required="required">
<input type="checkbox" name="section_5[1][anst]" id="anst-check-5-1" required="required" checked="checked">
<textarea onkeyup="textAreaAdjust(this)" name="section_5[1][com]"></textarea>
- anso, anst и com постоянны.
Я пытаюсь поймать POST формы следующим образом:
$answer_sections = array (); // anso , anst , com
$section_count = 1; // set to one to handle just thefirst section for testing.
$answer_section_index = 0;
$section_index = 5;
while($section_count > 0){
$answer_sections[$answer_section_index] = isset($_POST['section_'.$section_index]) ? $_POST['section_'.$section_index] : '';
$section_index++;
$answer_section_index++;
$section_count--;
}
Я ожидаю, что $ answer_sections [0] будет массивом, который содержит все шаги и их ответы. Однако, если я сделаю sizeof ($ answer_sections [0]), я получу:
PHP Предупреждение: sizeof (): параметр должен быть массивом или объектом, который реализует Countable
Что является первой из многих ошибок, которые я получаю.
Я использую ошибки многомерного массива? Я думаю, что я понял, что, если у вас одно и то же имя ввода, которое в данном случае равно «section_1», оно будет обрабатываться как массив в PHP.
Дамп такой:
array(11) {
[1]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [2]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [3]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [4]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [5]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [6]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [7]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [8]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [9]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [10]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
} [11]=> array(2) {
["anso"]=> string(2) "on" ["com"]=> string(0) ""
}
}
Array ( [1] => Array ( [anso] => on [com] => ) [2] => Array ( [anso] => on [com] => ) [3] => Array ( [anso] => on [com] => ) [4] => Array ( [anso] => on [com] => ) [5] => Array ( [anso] => on [com] => ) [6] => Array ( [anso] => on [com] => ) [7] => Array ( [anso] => on [com] => ) [8] => Array ( [anso] => on [com] => ) [9] => Array ( [anso] => on [com] => ) [10] => Array ( [anso] => on [com] => ) [11] => Array ( [anso] => on [com] => ) )
Буду признателен, если кто-нибудь сможет помочь.
Спасибо!