如何解决单击php中的提交按钮后如何使用id获取此名称
现在我想在提交此表单以将这一系列问题上传到数据库时使用 id 获取这个名称。我应该在下面的代码中使用什么:
<form action="forms/handle-questions.php" method="post">
<?php foreach ($questions $key => $question) : ?>
<div class="row">
<?= $question['question'] ?>
</div>
<div class="form-check ">
<input class="form-check-input" type="radio" name="radio_<?= $question['id'] ?>"
value="good">
<label class="form-check-label"> good</label>
</div>
<div class=" form-check ">
<input class="form-check-input" type="radio" name="radio_<?= $question['id'] ?>"
value="medium">
<label class="form-check-label" >medium</label>
</div>
<div class="form-check ">
<input class="form-check-input" type="radio" name="radio_<?= $question['id'] ?>"
value="weak">
<label class="form-check-label">weak</label>
</div>
<?php endforeach ?>
<button type="submit" name="handle_questions">Done</button>
</form>
解决方法
我通常做的事情是这样的
在表单发布后的 PHP 中
foreach($_POST as $key => $val) {
if (strpos($key,'radio_') !== false) {
$question_id = str_replace('radio_','',$key);
// now you have the question id that this radio value applies to
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。