简体   繁体   English

如何跟踪来自 php 回显表的响应

[英]how to track responses from a php echo form

I have code in a while loop that ultimately echoes out 30 questions.我在 while 循环中有代码,最终会产生 30 个问题。 Since its iterating with the same code just different variable values, I cannot track a tag to use _POST with.由于它使用相同的代码迭代只是不同的变量值,因此我无法跟踪要使用 _POST 的标签。

Is there anyway for me to store all the answers the user chooses while using a while loop?无论如何,我是否可以存储用户在使用 while 循环时选择的所有答案?

code:代码:

  while (counter !=0) {
        echo '
            <form method="post">

                <input type="radio" id="answerA" name= "answerA " value="answerA" required> 
                <label for="answerA"> ' . $row['answerA'] . ' </label><br>
                <input type="radio" id="answerB" name="answerB" value="answerB"> 
                <label for="answerB"> ' . $row['answerB'] . ' </label><br>
                <input type="radio" id="answerC" name="answerC" value="answerC"> 
                <label for="answerC"> ' . $row['answerC'] . ' </label><br>
                <input type="radio" id="answerD" name="answerD" value="answerD">
                <label for="answerD"> ' . $row['answerD'] . ' </label><br>


            </form>
        '
        ;

}

Put the row ID in a hidden input.将行 ID 放在隐藏的输入中。 The you can use $_POST['id'] to know which question it's the answer to.您可以使用$_POST['id']来知道它是哪个问题的答案。

while (counter !=0) {
    echo '
        <form method="post">

            <input type="radio" id="answerA-' . $row['id'] . '" name= "answer-' . $row['id'] . '" value="answerA" required> 
            <label for="answerA-' . $row['id'] . '"> ' . $row['answerA'] . ' </label><br>
            <input type="radio" id="answerB-' . $row['id'] . '" name="answer-' . $row['id'] . '" value="answerB"> 
            <label for="answerB-' . $row['id'] . '"> ' . $row['answerB'] . ' </label><br>
            <input type="radio" id="answerC-' . $row['id'] . '" name="answer-' . $row['id'] . '" value="answerC"> 
            <label for="answerC-' . $row['id'] . '"> ' . $row['answerC'] . ' </label><br>
            <input type="radio" id="answerD-' . $row['id'] . '" name="answer-' . $row['id'] . '" value="answerD">
            <label for="answerD-' . $row['id'] . '"> ' . $row['answerD'] . ' </label><br>
            <input type="hidden" name="id" value="' . $row['id'] . '">

        </form>
    '
    ;

}

There are other issues.还有其他问题。 IDs have to be unique, so you should include the question ID in the IDs of each of the answers. ID 必须是唯一的,因此您应该在每个答案的 ID 中包含问题 ID。

All the names in a radio group have to be the same, that's how the browser knows they're alternative answers to the same question.无线电组中的所有名称都必须相同,这就是浏览器知道它们是同一问题的替代答案的方式。 But each form needs to have distinct radio groups.但是每种形式都需要有不同的广播组。 So you should take A , B , C and D out of the radio button names, but add in the question ID.因此,您应该从单选按钮名称中取出ABCD ,但添加问题 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM