douji8347 2014-10-27 09:28
浏览 46
已采纳

CakePHP $ ajax->在客户端验证后提交提交

I am new to cakePHP, I have submit button in cakePHP

$ajax->submit( 'Submit', array( "update" => "gridbox_script", "url" => '/flots/comparaison_gridbox_update', "div"=>"button_submit", "loading" => "setIboxOpacity = setOpacity;showBG();showIndicator();" , "complete" => "hideBG();hideIndicator()" ) );

I would like to add one javascript validation, if the validation returns true then it should proceed for submission otherwise submission should be terminated.

The whole submission is calling through ajax and I was advised to use $ajax to implement.

my javascript function:

var firstCompare = new Array();
fucntion myValidation(){    
var otherCompare = new Array();
if(document.getElementById("file1").checked)
otherCompare.push('file1');
result = (otherCompare.length === _.intersection(otherCompare, firstCompare).length); 
firstCompare = otherCompare;
return result;
}

Please help me.

  • 写回答

1条回答 默认 最新

  • dragonpeng200811111 2014-10-27 09:36
    关注

    use the for id and check on submit or click event of your button.

    $(document).ready(function() {
        $('#formId').on('submit', function() {
            var val = your_function()  //call the function and store the return value
            if (val) {
               //do the submission
            } else {
              //code in case of false
            }
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?