php - 单击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
}
}
推荐阅读
- uipath - uipath错误单击onbeforeunload弹出窗口在chrome中不起作用
- html - 当链接文本跨越多行时,最小化链接行之间的空间
- android - 您可以解压缩已签名的 APK 吗?
- asp.net - 如何在同一张表中定义两个FK?
- caching - 带有 VirtualBox Runner 的 Gitlab CI 缓存
- push-notification - 使用 Nativescript(使用 javascript)配置 Onesignal
- python - Python 参数解析;如果参数 1 不存在,如何继续并设置所需的下一个参数
- c - hmac sha256 输出长度
- ruby-on-rails - Rails 5,使用 Microsoft 帐户登录 (Office 365)
- python - 如何找到 python 模块包含的 DLL 文件的完整路径?