我希望在发送联系表格7的电子邮件后,将联系表格7的内容提交给外部CRM。
如何检索表单数据?
我应该使用哪个钩子?
如何将表单提交给外部网址?
谢谢,
萨姆
答案 0 :(得分:8)
要在邮件发送后访问提交的表单,您可以执行以下操作:
// hook your function to wpcf7_mail_sent
add_action( 'wpcf7_mail_sent', 'handle_form_submission' );
function handle_form_submission( $contact_form ) {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
// handle the data here e.g. submit to CRM
}
}
答案 1 :(得分:3)
您可以通过添加以下操作来访问提交的数据。 对于OOP的
add_action('wpcf7_before_send_mail',array($this,'create_new_user_registration'),10,1);
用于简单的函数调用 -
add_action('wpcf7_before_send_mail','create_new_user_registration',10,1);
添加此操作后,您需要创建一个功能。在该功能中,您可以访问提交的数据 -
public function create_new_user_registration($contact_form)
{
$wpcf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
//Below statement will return all data submitted by form.
$data = $submission->get_posted_data();
//suppose you have a field which name is 'email' then you can access it by using following statement.
$user_passed_email = $data['email'];
}
与上述示例类似,您可以访问联系表单7提交的任何表单字段。