doupingpeng7567 2017-05-10 10:46
浏览 28

数据显示在表单上但不保存到db

I got stack i tried to custom code but the script did not saved the echo value into the DB.

here what I am doing so far:

function give_basic_fees_js() {
    ?>
    <script>
        <?php //Generate

$digits_needed=3;

global $random_number;

$random_number =''; // set up a blank string

$count=0;

while ( $count < $digits_needed ) {
    $random_digit = mt_rand(0, 9);

    $random_number .= $random_digit;
    $count++;
}?>
        var give_global_vars;
        //JS for Basic Fee calculation on the fly.
        jQuery(function ($) {
            /**
             * Event Triggers
             */
            //When document runs.
            $(document).ready(give_basic_update_percentage());
            //If donation amount update is triggered.
            $(document).on('give_donation_value_updated', function () {
                give_basic_update_percentage();
            });
            //If the donation.
            $(document).on('blur', '.give-donation-amount .give-text-input', function (e) {
                give_basic_update_percentage();
            });
            /**
             * JS update logic - Basic update percentage JS.
             */
            function give_basic_update_percentage() {
                //Set vars
                var percentage = <?php echo $random_number; ?>;
                var current_total = $('input[name="give-amount"]').val();
                //Unformat current total so fee calculation is correct for larger donations.
                current_total = Math.abs(parseFloat(accounting.unformat(current_total, give_global_vars.decimal_separator)));
                var fee = percentage;
                var new_total = current_total + fee;
                //Set the custom amount input value format properly
                var format_args = {
                    symbol: give_global_vars.currency_sign,
                    decimal: give_global_vars.decimal_separator,
                    thousand: give_global_vars.thousands_separator,
                    precision: give_global_vars.number_decimals
                };
                fee = accounting.formatMoney(fee, format_args);
                new_total = accounting.formatMoney(new_total, format_args);
                //Update fee information text.
                $('span.give-basic-fee-amount').text(fee);
                //Update final total text.
                $('.give-final-total-amount').text(new_total);
            }
        });
    </script>
<?php }
add_action( 'wp_print_footer_scripts', 'give_basic_fees_js' );
/**
 * Adds the fee to the DB upon submit.
 *
 * @param $sanitized_amount
 *
 * @return string
 */
function give_basic_fees_add_fee( $sanitized_amount ) {
    //$fee_percentage = (int) give_get_option( 399 );
    $fee            = $sanitized_amount;
    $new_total      = $fee + percentage;
    return $new_total;
}
add_filter( 'give_donation_total', 'give_basic_fees_add_fee', 1, 1 );

So I want to record into DB the $new_total value with formula fee + random_number of percentage

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?