These are the buttons on my form:
<input type="submit" id="form-submit" class="btn" name="save" value="verzenden" />
<input type="submit" name="cancel" class="btn" value="annuleren" />
I catch the cancel click with php like this:
if($_POST['cancel'])
{
Helper::redirect('page.php');
}
But before I submit my form, I use some jQuery to validate the form, now I can’t click cancel because it will validate first.
This is my jQuery code:
<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>
How can I ignore the jQuery and redirect to page.php when I hit cancel?
Thanks
This is what I got now:
Thanks ThiefMaster
//javascript
//php
//html