php - 选择字段中的必需标签不起作用
问题描述
我尝试将所需的属性添加到我的选择标签中。不幸的是,这被忽略了。下拉列表由数据库条目动态填充。有谁知道为什么?是动态元素的错吗?
<div class="input-field col s12 m6 l6">
<?php
//-------------------------------------------//
$statement = $pdo->prepare("SELECT * FROM availableCards WHERE Active = '1' ORDER BY Description");
$statement->execute();
echo '<select name="images" id="images" required>';
echo '<option value="" disabled selected>Bitte wählen</option>';
while ($data = $statement->fetchAll(PDO::FETCH_ASSOC)) {
foreach ($data as $row) {
echo '<option name="' . $row['Value'] . '" value="' . $row['Value'] . '" data-icon="../cards/' . $row['ImagePath'] . '">' . $row['Description'] . '</option>';
}
}
echo '</select>';
//-------------------------------------------//
?>
<label for="images">Karte auswählen</label>
</div>
解决方案
复制并粘贴以下块。您拥有的表单可能没有正确嵌套。
<form action="/">
<div class="input-field col s12 m6 l6">
<?php
$data = array(
'1' => 'One',
'2' => 'Two',
'3' => 'Three',
);
//-------------------------------------------//
echo '<select name="images" id="images" required>';
echo '<option value="" disabled selected>Bitte wählen</option>';
foreach ($data as $row) {
echo '<option name="' . $row['Value'] . '" value="' . $row['Value'] . '" data-icon="../cards/' . $row['ImagePath'] . '">' . $row['Description'] . '</option>';
}
echo '</select>';
//-------------------------------------------//
?>
<label for="images">Karte auswählen</label>
<button type="submit" name="button">Bestätigen</button>
</div>
</form>
请添加结束表单标签和最后一个 div 的。StackOverflow 的嵌入代码是一场噩梦。
推荐阅读
- c++ - 如何使用 tcp 连接发送大块数据
- node.js - 如何获取googlesheet中的第一个空单元格
- machine-learning - ANN 模型能否适用于不同数量的输入?
- java - 从 Json 数组中获取数据
- string - 从 Pandas DataFrame 中的所有行和列中去除标点符号
- c - 为什么函数 SDL_WaitEvent (SDL2) 在我的代码中出现错误?
- css - 悬停后元素“跳跃”
- python - 使用 OpenCV 检测小数点
- c - fopen 导致分段错误
- c# - 编写一个在 DbContext 重新评估之间重新评估的 LambdaExpression?