在我的HTML表单中的所有数据成功,除了复选框值验证复选框值。它不验证与jquery/ajax请求。无法验证与jQuery/AJAX
这里是我的html表单AJAX和HTML代码(仅条款部分):
<tr>
<td>Terms & Conditions</td>
<td><input type="checkbox" name="terms"/> I agree to your <a href="">terms and
conditions</a>.</td>
<script>
$('#form1').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'regProcess.php',
data: $(this).serialize(),
dataType: 'json',
success: function (data) {
$('#info1').html('');
$.each(data, function(key, value) {
$('#info1').append('<p>'+value+'</p>');
});
}
});
});
</script>
在regProcess.php页以下是我的复选框验证代码,但它不是验证..
if(isset($_POST['terms']) && $_POST['terms'] == ""){
$msg[] = "You must agree our terms and conditions";
$msg1['error'] = true;
}
看到这个http://stackoverflow.com/questions/11424037/does-input-type-checkbox-only-post-data-if-its-checked – KrIsHnA
在这里你可以得到一个回答:http://stackoverflow.com/questions/19893927/send-checkbox-value-in-php-form – KrIsHnA