【问题标题】:How to redirect after form submission in contact form 7?如何在联系表单 7 中提交表单后重定向?
【发布时间】:2015-09-18 11:08:07
【问题描述】:

我正在使用联系表格 7 提交表格并使用 wpcf7_before_send_mail 通过soap 客户端生成参考号。

代码是

function wpcf7_do_something($WPCF7_ContactForm)
{

    if (3490 == $WPCF7_ContactForm->id()) {
      $client = new SoapClient('http://xxx.xxx.xxx.xxx:xxxxx/4dwsdl', array('trace' => 1));
   $res_date = date("Y-m-d", strtotime('01 feb 2015'));
   $enquiry_id = $client->__call('WS_AddContact',  
       array(
           'narwal Devender',
           null,
           'Devender',
           'narwal',
           'hisar',
           'Hisar',
           'Haryana',
           '125001',
           'Australia',
           '01662246138',
           '9802260750',
           '8529000369',
           'vijaylal@webmastershisar.com',
           true,
           'google',
           'google',
           'Phone Call',
           0,
           'type of good should be strode.',
           $res_date,
           '2 to 6  Months',
           'SSPSS',
           null,//array('xxxxxxx'),
           array('46.75'),
           array('1 x 1 x 1 (1qm)'),
           array('xxxxxxxxx'),
           array('send print should be here to work.'),
           null,
           'xxxxxxxxxxxxx',
           null
       )
   );


   mail('vijaylal@webmastershisar.com', 'My Subject', $enquiry_id); 

  }
  return $wpcf7;
}

这工作正常并正在发送电子邮件。

但我想在感谢页面或任何页面上向自定义显示查询 ID,或者通过使用一些重定向并将数据发送到 url。

我也在尝试在 wpcf7_mail_sent 中使用此代码,这也可以,

但是当我尝试使用重定向时,它什么也不做,并且联系表格只是挂起。

add_action('wpcf7_mail_sent', 'wpcf7_redirect_on_submit');

function wpcf7_redirect_on_submit($wpcf7)
{
        header( 'Location: http://www.google.com' );
        exit;
}

如何在不使用 javascript 或 jQuery on_sent_ok 的情况下重定向 wpcf7_mail_sent 中的联系表单?

如何在页面上向用户显示此查询 ID?

任何人都可以帮助完成这项工作。

【问题讨论】:

    标签: php wordpress soap-client contact-form


    【解决方案1】:

    您还可以使用可用的挂钩来更改属性

    add_filter( 'wpcf7_contact_form_properties', 'let_me_redirect', 10, 2 );
    /**
     * Add the code that will run when on_sent_ok is triggered;
     */
    function let_me_redirect( $properties, $contact_form_obj){
     $properties[ 'additional_settings' ] .="on_sent_ok: \"location.replace('http://www.google.com');\""
     ;
     return $properties;
    }
    

    【讨论】:

    • 这只是我们可以做的一个例子。我更改了代码。现在检查
    • 亲爱的你是对的,我刚刚接近结果,但我只是想在我的网址中插入 $userid,比如$properties[ 'additional_settings' ] .="on_sent_ok: \"location.replace('http://soandso.com/thankyou/?enquryid='".$key_1_value.");\"";,但这不起作用
    • 您是否为 $key_1_value 添加了价值?因为它对我有用
    • 谢谢亲爱的你救我。正确的字符串是 '$properties[ 'additional_settings' ] .="on_sent_ok: \"location.replace('soandso.com/thankyou/?enquryid=".$key_1_value."');\"" ; ' .我在字符串中犯了一些错误。
    • 虽然这不是我所要求的正确方式...我通过更新 wpcf7_before_send_mail 中的用户元数据并在 wpcf7_contact_form_properties 中获取用户元数据来做一些事情。
    猜你喜欢
    • 2017-09-28
    • 2015-05-05
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    相关资源
    最近更新 更多