## Trigger URL (webservice) after cf7 submission

Question

I have a question for you

For one of my client i need to trigger a webservice after cf7 submission (not redirect after submission, juste send parameters to a specific url), in order to register the client’s e-mail to an external webservice.

To be more specific i have something like this

add_action('wpcf7_before_send_mail', 'save_application_form');
function save_application_form($wpcf7) { //global$wpdb;
$wpcf7 = WPCF7_ContactForm :: get_current();$submission = WPCF7_Submission::get_instance();



Here i pass an action filter in order to grab the mail before it is send

 if ($submission){$posted_data = $submission->get_posted_data() ; // nothing's here... do nothing... if ( empty ($posted_data))
return ;


Here i check if the submission is not empty

    $subject =$posted_data['your-message'];

// grab the data sent by the users
$e_mail =$_POST['E-mail'];
$guid_csm =$_POST['cate'];
$origine_csm =$_POST['ori'];

switch ($guid_csm) { case "case1":$qualification = "11111";
break;
case "case2":
$qualification = "22222"; break; case "case3":$qualification = "33333";
break;
case "case4":
$qualification = "44444"; break; case "case5":$qualification = "55555";
break;
case "case6":
$qualification = "66666"; break; case "case7":$qualification = "77777";
break;
case "case8":
$qualification = "88888"; break; };  Here i grab the data collected by the mail form and i make a switch to convert some of them into guid for my webservice (i change the real case value into fake one, but the logic is still the same) //Build the URL with attempted parameters$urlconstruct = 'https://super.webservice/super/webservice/?email='.date("YmdH:i:s").'_'.$e_mail.'&lists='.$qualification.'&origin='.$origine_csm.'' ; return$WPCF7_ContactForm ;
}

}


Here i construct the Attempted URL with the paramaters that i’ve collected in the form and return the form in order to send the mail normaly

But now i’m quite lost, i’ve created the url that i need to pass to the webservice, but how do i use this url ? i’ve read somewehre on the net that i need to use curl ?

I’ve tried something with it, next to the php doc, but can’t be able to make it work .

I precise that i can’t touch the webservice, it is developped by a developper of my client, and he just passed me some URL example to build my own, based on the form answers.

I also have to precise that when the service is register properly some new e-mails, the answere return by it is blank, and when i have an error it throw me a json array that i have to decode
(i think about json_decode with a foreach loop or something )

Any idea ?

(For those who want the entire code)

add_action('wpcf7_before_send_mail', 'save_application_form');
function save_application_form($wpcf7) { //global$wpdb;
$wpcf7 = WPCF7_ContactForm :: get_current();$submission = WPCF7_Submission::get_instance();

if ($submission){$posted_data = $submission->get_posted_data() ; // nothing's here... do nothing... if ( empty ($posted_data))
return ;

$subject =$posted_data['your-message'];

// grab the data sent by the users
$e_mail =$_POST['E-mail'];
$guid_csm =$_POST['cate'];
$origine_csm =$_POST['ori'];

switch ($guid_csm) { case "case1":$qualification = "11111";
break;
case "case2":
$qualification = "22222"; break; case "case3":$qualification = "33333";
break;
case "case4":
$qualification = "44444"; break; case "case5":$qualification = "55555";
break;
case "case6":
$qualification = "66666"; break; case "case7":$qualification = "77777";
break;
case "case8":
$qualification = "88888"; break; }; //Build the URL with attempted parameters$urlconstruct = 'https://super.webservice/super/webservice/?email='.date("YmdH:i:s").'_'.$e_mail.'&lists='.$qualification.'&origin='.$origine_csm.'' ; return$WPCF7_ContactForm ;
}

}


Thanks all for your spend time on my problem =)

0
3 years 2019-10-22T02:23:23-05:00 0 Answers 69 views 0