我正在设计一个测验软件,其中的问题以试卷的形式列出。用户假设只准确回答一个问题和一个答案。我的问题是,对于每个问题和 3 个选项,我都有不同的表格。提交后,我想知道在提交的各种表单中选中了哪个单选按钮。代码是这样的。
<html>
<form name="one" action="me.php" method="post">
<input type="radio" name=" subject " value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>
<form name="one" action="me2.php" method="post">
<input type="radio" name=" subject " value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>
<form name="one" action="me3.php" method="post">
<input type="radio" name=" subject " value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>
<form name="one" action="me4.php" method="post">
<input type="radio" name="subject" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>
</html>
谢谢
最佳答案
不要使用多种形式,而是这样做,
<html>
<form name="one" action="me.php" method="post">
<input type="radio" name="subject_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="subject_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="submit" value="submit">
</form>
</html>
其中 dbid
是您的数据库。
确保 dbid
是您问题的 ID。(主题和选项应该相同。)
对于您帖子中的第一个问题,subject_1
和 option_1
将选择该问题。
要访问 php 中的问题和答案,请在 php 中使用 explode()
和 _
。
$arr[1]
将具有数据库 ID。您可以轻松地将答案与数据库进行匹配。
关于javascript - 多种表单和单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33705031/