开发者

cancel button php form jquery

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');
        }开发者_如何学Python); 
    });
</script>

How can I ignore the jQuery and redirect to page.php when I hit cancel? Thanks


$('#cancel').delegate('','click change',function(){
    console.log('test');
});

This will not work, while you don't have any element in your form with id cancel

Change that button

<input type="submit" name="cancel" class="btn" value="annuleren" />

to

<input type="submit" id="cancel" name="cancel" class="btn" value="annuleren" />


This is what I got now:
Thanks ThiefMaster

//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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜