空の場合は、フィールドのフィールドを検証する関数があります。trueまたはfalseの場合、関数の戻り値を確認する方法
function ValidateForm()
{
jQuery('span.error_msg').hide();
var success = true;
jQuery("#shippingF input").each(function()
{
if(jQuery(this).val()=="")
{
jQuery(this).next().show();
success = false;
}
});
return success;
}
は今、私はここでその機能を使用したい:
function post(url,formId) {
jQuery("#process").html('<img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/ajax-loader.gif'; ?>" alt="loading" title="ajax-loader" width="16" height="16" class="alignnone size-full wp-image-134">');
jQuery.post(url, jQuery('#' + formId).serialize(), function(d) {
jQuery('html,body').animate({scrollTop: jQuery("#scrollhere").offset().top},'slow');
jQuery("#response").html('<center><p style="height:820px"><span style="color:black;font-weight:bold;font: 11px arial,verdana,sans-serif;"><b>Loading available payment getaways..</b></span><br/><img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/8-1.gif'; ?>" width="220" height="19" /></p></center>');
jQuery("#response").load("<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/checkout_payment.php'; ?>", function() { Cufon.refresh(); });
jQuery("#response").attr("style","height:1030px");
});
}
私はそれを試してみましたが、私はこれを思い付きます。
function post(url,formId) {
ValidateForm();
if(ValidateForm() == 'false') {
jQuery('html,body').animate({scrollTop: jQuery("#shippingF").offset().top},'slow');
} else {
jQuery("#process").html('<img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/ajax-loader.gif'; ?>" alt="loading" title="ajax-loader" width="16" height="16" class="alignnone size-full wp-image-134">');
jQuery.post(url, jQuery('#' + formId).serialize(), function(d) {
jQuery('html,body').animate({scrollTop: jQuery("#scrollhere").offset().top},'slow');
jQuery("#response").html('<center><p style="height:820px"><span style="color:black;font-weight:bold;font: 11px arial,verdana,sans-serif;"><b>Loading available payment getaways..</b></span><br/><img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/8-1.gif'; ?>" width="220" height="19" /></p></center>');
jQuery("#response").load("<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/checkout_payment.php'; ?>", function() { Cufon.refresh(); });
jQuery("#response").attr("style","height:1030px");
});
}
}
問題は検証が働いている...しかし、.post()
関数が空のフィールドがあっても実行される、ということです。私はif/else条件でそれを推測する。これを達成するための良い方法があるのだろうか?
ありがとうございます。
ValidateFormを2回呼び出す理由はありますか? –
問題は、 'ValidateForm();'が 'post()'関数に含まれていないとエラーメッセージが表示されない.. – Ken
これはすでにif内部で呼び出されています。それ以前にもう一度呼び出す必要はありません。 –