我已多次尝试下拉列表验证, 我的代码是用PHP和HTML编写的,验证部分不起作用,我在stackoverflow中引用了一些类似于我的类似案例的解决方案。
声明变量
$call_department = $db->escape((int)$_POST['call_department']); //where i declare this variable
HTML文件
<tr><td>Department</td><td><select name='call_department'>
<option></option>
<?php $call_dept = $db->get_results("select type_id,type_name from site_types where type=1 order by type_name;");
foreach ($call_dept as $dept )
{?>
<option value='<?php echo $dept->type_id;?>'><?php echo $dept->type_name; required?></option>
<?php } ?>
</select></td></tr>
验证部分:
<?php
if(isset($_REQUEST['call_department']) && $_REQUEST['call_department'] == '0') {
echo 'Please select a department.';
}
?>
答案 0 :(得分:1)
1)像这样设置第一个选项Required
<select name='call_department' required>
2)<select name='call_department' required>
<option value="0">select</option>
<?php $call_dept = $db->get_results("select type_id,type_name from site_types where type=1 order by type_name;");
foreach ($call_dept as $dept )
{
?>
<option value='<?php echo $dept->type_id;?>'><?php echo $dept->type_name; ?></option>
<?php } ?>
</select>
属性应设置为选择标记而不是选项标记@Component("shiroSecurityConfig")
public class ShiroSecurityConfig {
@Autowired (required = true)
private TestService testService;
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilter() {
testService.getrecords(); //this line got null pointer exception.
}
}
{{1}}