これに近い他の例を見ましたが、まだ問題があるようです。問題は、以下の3番目のエラーチェッカーのスクリプト(#bid <#budm)です。入札フィールドの額は、#budmが保存する必要がある予算の設定額を下回ることはできません。 phpを使用して、post idに関するデータベースから#budmの値を取得します。その変数をjsエラーチェッカーに渡そうとすると、php変数を格納する隠し入力フィールド(id = "budm")とユーザー入力フィールド(id = "bid")を比較します。ランダムに作業するようです。たとえば、$ budgetminの値が400の投稿では、400以下のほとんどのエントリは受け入れられませんでしたが、何らかの理由で値が9になりました。PHP変数をjavascript/jqueryに渡してエラーチェックします
<?php
global $current_user;
get_currentuserinfo();
$cid = $current_user->ID;
$cwd = str_replace('wp-admin','',getcwd());
$post = get_post($pid);
$budgetmin = get_post_meta($pid, 'budget_start', true); ?>
<input type="hidden" id="budm" value="<?php echo $budgetmin; ?>">
<script type="text/javascript">
function check_submits()
{
if(jQuery("#days_done").val().length == 0)
{
alert("<?php _e('Error text3'); ?>");
return false;
}
if(jQuery("#bid").val().length == 0)
{
alert("<?php _e('Error text2'); ?>");
return false;
}
if (jQuery('#bid').val() < jQuery('#budm').val())
{
alert("<?php _e('Error text'); ?>");
return false;
}
return true;
}
</script>
<input type="text" name="bid" id="bid" class="bid_field" value="<?php echo $bid; ?>" size="10" />
<input class="green_btn grey" style="font-size: 20px; padding-left: 15px; padding-right: 15px; font-weight: 400;" id="submits_crt" type="submit" name="bid_now_reverse" value="<?php echo "Submit"; ?>" />
ご協力いただきまして誠にありがとうございます。
まず、ブラウザのコンソールでエラーがないか確認します。次に、jQueryが* no-conflictモード*で使用されているかどうかを確認します。 – dekkard
これは疑問だと言いますが、コードを実行するとどうなりますか? – colonelsanders
返信いただきありがとうございます!だから... - $ budgetmin = 100 - ユーザーは#bid入力フィールドに10を入力します - エラーチェックが正しく実行されます。 -userは#bidに50を再送信します - エラーチェックに失敗し、値50が除外されます。 –