How to redirect after submitting a form to contact form 7?
I am using contact form 7 to submit a form and generate a reference number via a soap client using wpcf7_before_send_mail.
Code
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'));
$enquiery_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',$enquiery_id);
}
return $wpcf7;
}
This works fine and sends email.
But I want to show the custom request id on the thank you page or any page or by redirecting and sending data to url.
I am also trying to use this code in wpcf7_mail_sent, this also works,
But when I try to use the redirect it doesn't do anything and the contact form just hangs.
add_action('wpcf7_mail_sent', 'wpcf7_redirect_on_submit');
function wpcf7_redirect_on_submit($wpcf7)
{
header( 'Location: http://www.google.com' );
exit;
}
How to redirect contact form to wpcf7_mail_sent without using javascript or jquery on_sent_ok?
or
How can I show this request ID to the user on the page?
Can anyone help make this work.
+3
source to share
1 answer
You can also use the available hook to change properties
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;
}
+1
source to share