Php JQuery Ajax从联系人表单7多步骤表单Wordpress发送数据

Php JQuery Ajax从联系人表单7多步骤表单Wordpress发送数据,php,jquery,ajax,wordpress,contact-form-7,Php,Jquery,Ajax,Wordpress,Contact Form 7,我想从php文件中的Contact Form 7多步骤表单发送数据。每个步骤有1-4个字段。所以我想通过电子邮件发送相同的数据也发送到php文件。 发送到电子邮件的数据如下: Internet: [radio-internet] Mobile: [radio-mobile] Provider: [radio-provider] Surname: [your-surname] Name: [your-name] Email: [your-email] Phone: [your-phone] Hou

我想从php文件中的Contact Form 7多步骤表单发送数据。每个步骤有1-4个字段。所以我想通过电子邮件发送相同的数据也发送到php文件。 发送到电子邮件的数据如下:

Internet: [radio-internet]
Mobile: [radio-mobile]
Provider: [radio-provider]
Surname: [your-surname]
Name: [your-name]
Email: [your-email]
Phone: [your-phone]
Hours: [radio-hours]
我尝试过类似的方法,但不起作用:

<script type="text/javascript">
document.addEventListener( 'wpcf7submit', function( event ) {
    //Form
    var inputs = event.detail.inputs;

    for ( var i = 0; i < inputs.length; i++ ) {
    if ( 'radio-internet' == inputs[i].name &&  'radio-mobile' == inputs[i].name &&  && 'radio-provider' == inputs[i].name && 'your-surname' == inputs[i].name &&  'your-name' == inputs[i].name  &&  'your-email' == inputs[i].name  &&  'your-phone' == inputs[i].name  &&  'radio-hours' == inputs[i].name ) {
        jQuery.ajax({
            url  : 'process.php', // the url where we want to POST 
            type : 'post',
            data :  inputs,
            success : function( response ){
                console.log(response);
                console.log('lead inserted');
            },
            error : function(e1, e2, e3){
                console.log(e1);
                console.log(e2);
                console.log(e3);
            }
        });
        console.log( event.detail );
    }

}, false );
</script>

为此,您可以使用电子邮件发送前的联系表7

现在我只是将数据存储在一个文本文件中,您可以在这里添加逻辑

 add_action( 'wpcf7_before_send_mail', 'd_before_send_email' );

 function d_before_send_email($cf7) {
    $output = "";
    $output .= "Name: " . $_POST['name'];
    $output .= "Email: " . $_POST['email'];       

    file_put_contents("contactform7output.txt", $output);
   }

尝试使用“wpcf7mailsent”事件,它对我很有用

document.addEventListener( 'wpcf7mailsent', function( event ) {
    
            var inputs = event.detail.inputs;
    
            
                var username = document.getElementById('username').value; // OR jQuery( "#username" ).val();

                var email = document.getElementById('email').value; // OR jQuery( "#email" ).val();
                
    
                jQuery.ajax({
                   url  : <?php echo admin_url('admin-ajax.php'); ?>, // the url where we want to POST 
                type : 'post',
                data :  {action:second_form,username:username,email:email},
                success : function( response ){
                    console.log(response);
                    
                },
                  error: function(response) {
                    console.log(response);
                  },
                });
                alert('hi');
            
    
        }, false );

你想用这些数据做什么?因为联系人表单7有一些过滤器,你可以使用它们做很多事情。那么,告诉我为什么要在php文件中使用这些数据?我希望这些数据也在vtiger crm的“上次提交时自动发送”按钮中发送。联系人表单id 123是最后一个表单?如何从所有表单读取数据,因为我使用的是Contact Form 7 Multi-Step Form.remove if条件,这只是一个示例我收到一个错误:(索引):383 Uncaught TypeError:无法读取null的属性“value”。383 var internet=document.getElementById('radio-internet')。值;所以不能从其他表单读取数据?这对我不起作用。。。如何保存来自其他表单的数据,并在将所有数据发送到我们要发布数据的url之后?在我看到的每个步骤中,当我单击提交按钮发送每个表单时,您的解决方案都会在每个表单中发送数据
document.addEventListener( 'wpcf7mailsent', function( event ) {
    
            var inputs = event.detail.inputs;
    
            
                var username = document.getElementById('username').value; // OR jQuery( "#username" ).val();

                var email = document.getElementById('email').value; // OR jQuery( "#email" ).val();
                
    
                jQuery.ajax({
                   url  : <?php echo admin_url('admin-ajax.php'); ?>, // the url where we want to POST 
                type : 'post',
                data :  {action:second_form,username:username,email:email},
                success : function( response ){
                    console.log(response);
                    
                },
                  error: function(response) {
                    console.log(response);
                  },
                });
                alert('hi');
            
    
        }, false );
add_action('wp_ajax_second_form' , 'second_form');
add_action('wp_ajax_nopriv_second_form','second_form');
function second_form(){
echo $_POST['username'];
echo $_POST['email'];
//do for second form
}