Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 联系表7邮件发送后,需要提交另一个隐藏表_Wordpress - Fatal编程技术网

Wordpress 联系表7邮件发送后,需要提交另一个隐藏表

Wordpress 联系表7邮件发送后,需要提交另一个隐藏表,wordpress,Wordpress,我有一张由联系人填写的表格7。成功发送表单数据后,我需要向外部CRM提交另一个隐藏表单。我的代码在下面 add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' ); function your_wpcf7_mail_sent_function( $contact_form ) { $title = $contact_form->id; $submission = WPCF7_Submission::get_instan

我有一张由联系人填写的表格7。成功发送表单数据后,我需要向外部CRM提交另一个隐藏表单。我的代码在下面

add_action( 'wpcf7_mail_sent', 'your_wpcf7_mail_sent_function' ); 
function your_wpcf7_mail_sent_function( $contact_form ) {
$title = $contact_form->id;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
    $posted_data = $submission->get_posted_data();
}
if ( 12 == $title ) {
$firstname = $posted_data['firstname'];
echo '<form name="bntWebForm" id="bntWebForm" method="post"action="https://www.bntouchmortgage.net/account5/webform/" style="display:none;">
<input class="form-control" type="text" name="name_1" value="'.$firstname.'" />
<input type="submit" value="Submit">
</form> ';
?>
<script>document.getElementById("bntWebForm").submit();</script>
<?php 
}
}
add_操作('wpcf7_-mail_-sent','your_-wpcf7_-mail_-sent_-function');
使用您的邮件发送功能($contact\u form){
$title=$contact\u form->id;
$submission=WPCF7_submission::get_instance();
如果($提交){
$posted_data=$submission->get_posted_data();
}
如果(12==$title){
$firstname=$posted_数据['firstname'];
回声'
';
?>
document.getElementById(“bntWebForm”).submit();

我认为你的方法基本上是错误的

wpcf7\u mail\u sent
操作发生在服务器端,无法用于将DOM元素添加到页面中。您尝试与javascript代码一起回显的表单将永远不会添加到页面中,并在您期望的客户端环境中运行

要将包含数据的post发送到所需的外部端点,仍然可以使用PHP curl函数使用
wpcf7\u mail\u sent
hook发送HTTP post请求

下面是一个例子:

add_action('wpcf7_mail_sent', function() {
   $endpoint_url = 'https://www.bntouchmortgage.net/account5/webform/';
   $data_to_post = ['name_1' => $firstname];

   // Sets our options array so we can assign them all at once
   $options = [
       CURLOPT_URL        => $endpoint_url,
       CURLOPT_POST       => true,
       CURLOPT_POSTFIELDS => $data_to_post,
   ];

   $curl = curl_init();
   curl_setopt_array($curl, $options);

   // Executes the cURL POST
   $results = curl_exec($curl);

   curl_close($curl);
});