如何在联系表单7提交后进行重定向?

4

我将使用联系表单7来提交表单,并通过SOAP客户端使用wpcf7_before_send_mail生成参考号。

代码如下:

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;
}

如何在wpcf7_mail_sent中重定向联系表格而不使用javascript或jQuery on_sent_ok?

或者

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

有人可以帮忙完成这项工作吗?

1个回答

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;
}

这只是我们可以做的一个例子。我已经修改了代码。现在请检查。 - Karun
亲爱的,你是对的,我离结果很近,但我只是想在我的URL中插入$userid,就像$properties [ 'additional_settings' ] .="on_sent_ok: \"location.replace('http://soandso.com/thankyou/?enquryid='".$key_1_value.");\"";但这没用。 - Vijay Lal
你有给$key_1_value添加值吗?因为它对我来说是有效的。 - Karun
谢谢你,你救了我一命。正确的字符串是'$properties['additional_settings'] .="on_sent_ok: "location.replace('http://soandso.com/thankyou/?enquryid=".$key_1_value."');\"";'。我在字符串中犯了一些错误。 - Vijay Lal
虽然这不是我所询问的正确方式...但我通过在wpcf7_before_send_mail中更新用户元数据并在wpcf7_contact_form_properties中获取用户元数据来进行了一些jugad。 - Vijay Lal
注意:这种方法将要从CF7中删除:“注意:不再建议使用使用on_sent_ok钩子的方法。该函数计划在2017年底被废除。” - icc97

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接