这些是我表单上的按钮:
<input type="submit" id="form-submit" class="btn" name="save" value="verzenden" />
<input type="submit" name="cancel" class="btn" value="annuleren" />
我用php捕捉到取消点击,如下所示:
if($_POST['cancel'])
{
Helper::redirect('page.php');
}
但在提交表单之前,我使用一些jQuery来验证表单,现在我不能单击取消,因为它将首先验证。
这是我的jQuery代码:
<script type="text/javascript">
$(document).ready(function(){
$('#cancel').delegate('','click change',function(){
console.log('test');
});
$('form').submit(function(){
var proceed = true;
$('.required').each(function(){
if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == '0') {
$(this).css('border-color', '#F00');
proceed = false;
}
else {
$(this).css('border-color', '#999');
}
});
return proceed;
});
// Check on typing if a required field is empty
$('.required').keyup(function(){
if ($(this).val() == '' || $(this).val() == 0 || $(this).val() == '0' )
$(this).css('border-color', '#F00');
else
$(this).css('border-color', '#999');
});
});
</script>
当我点击cancel时,如何忽略jQuery并重定向到page.php?感谢
$('#cancel').delegate('','click change',function(){
console.log('test');
});
这将不起作用,而您的表单中没有任何id取消的元素
更改按钮
<input type="submit" name="cancel" class="btn" value="annuleren" />
至
<input type="submit" id="cancel" name="cancel" class="btn" value="annuleren" />
这就是我现在得到的:
感谢盗贼大师
//javascript
$('#cancel').delegate('','click change',function(){
window.location = "testimonials.php";
return false;
});
//php
if($_POST['cancel'])
{
Helper::redirect('testimonials.php');
}
//html
<input name="cancel" type="submit" id="cancel" class="btn" value="annuleren" />