我无法让Gender的单选按钮注册错误。 我尝试了几种方法:
<input >
标记class="required"
放入输入标记validate({rule:{'fb[15]':{required:true}}}
这些选项都不会在js控制台中出错,但 none会触发验证错误,
如果我在提交时未选中性别选项。
我在页面的标题中有jQuery。我知道它正在运作。
<form action="https://example.com" method="post" id="formBuilder" class="formBuilder">
<p>
<label for="form-1"><span class="red">*</span> E-Mail Address</label>< br/>
<input maxlength="255" name="fb[1]" size="50" type="email" id="form-1" required/> <br/>
<label for="form-2"><span class="red">*</span> Full Name</label> <br/>
<input maxlength="255" name="fb[2]" size="50" type="text" required id="form-2"/> <br/>
<label><span class="red">*</span> Gender</label> <br/>
<input name="fb[15]" type="radio" value="0" id="form-15-0"/>
<label for="form-15-0">Male</label>
<input class="required" name="fb[15]" type="radio" value="1" id="form-15-1"/>
<label for="form-15-1">Female</label>
<label for="form-8"><span class="red">*</span> Request</label> <br/>
<textarea cols="40" name="fb[8]" rows="3" id="form-8" required></textarea> <br/>
<span><span class="red">*</span>= required information </span>
</p>
<span class="buttons">
<input name="submit" type="submit" value="Submit" id="form-submit"/>
</p>
</form>
<script src="/wp-includes/js/jquery.validate.min.js"></script>
<script>
$('#formBuilder').validate( );
</script>
答案 0 :(得分:1)
尝试将无线电输入的name
属性更改为其他名称,例如test
,不带 []
,这样就可以了name="test"
:
您的规则将是:
$('#formBuilder').validate({
rules: {
test: {
required: true
}
}
});