【问题标题】:Contact form 7 Variable to recall later联系表 7 稍后调用的变量
【发布时间】:2020-08-28 15:21:16
【问题描述】:

我希望在稍后的页面上调用 Contact Form 7 字段输入。当前流程是用户填写 cf7 表单,表单重定向到签名插件 (ApproveMe),然后使用 WPSimple Pay 重定向到支付页面。我有一个函数可以使用 HTML 变量自动将总金额添加到表单中。

我的functions.php 包含以下内容:

function simpay_custom_form_35_amount( $amount ) 
{

    $url_var = 'amount';
    $value = isset( $_GET[ $url_var ] ) ? sanitize_text_field( $_GET[ $url_var ] ) : $default;

    return $value;
}
add_filter( 'simpay_form_35_amount', 'simpay_custom_form_35_amount' );

这允许我设置要收取的表格数量:https://paymentpage/?amount=250

ISSUE/HELP WITH 我想做的是如果我的 URL 包含 ?amount=xxx 以使用 URL 设置,但如果 URL 未指定任何内容,则默认为之前提交的联系表单 7 值。

【问题讨论】:

  • 首先您必须在函数范围内定义$default。也许通过将其作为参数传入

标签: php wordpress function cookies contact-form-7


【解决方案1】:

使用

创建了一个cookie
(function($){
    $(document).on('click', '.wpcf7-submit', function(){
        if($('.total-cost .ctf7-total').length && $('.total-cost .ctf7-total').attr('data-number')){
            document.cookie = "sy_total_val="+$('.total-cost .ctf7-total').attr('data-number') + '; path=/';
        }
    });
})(jQuery);

total-cost 是我想通过的 cf7 中的字段。

然后将 cookie 设为默认值,但如果存在则用 URL 变量覆盖

function simpay_custom_form_35_amount( $amount ) {

    $url_var = 'amount';
    if(!empty($_COOKIE["sy_total_val"])) $default = sanitize_text_field($_COOKIE["sy_total_val"]);

    $value = isset( $_GET[ $url_var ] ) ? sanitize_text_field( $_GET[ $url_var ] ) : $default;

    return $value;
}
add_filter( 'simpay_form_35_amount', 'simpay_custom_form_35_amount' );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    相关资源
    最近更新 更多