0

I need to integrate a SOAP service with the WordPress plugin Contact Form 7.

In a simple HTML form, I've obtained this result passing via Ajax the form datas to an external PHP file. Here's the code:

HTML

<form id="newsletterForm" action="">
    <input id="emailField" type="email" name="email" placeholder="La tua email" data-validation="email" />
    <input id="submitButton" type="submit" onclick="submitNewsletter();">
</form>

JS

function submitNewsletter(){
            data=$('#newsletterForm').serialize();
            $.ajax({
            url: "soap.php",
            type:'POST',
            data:data,
            async:false,
            dataType:'html',     
        });
    }

SOAP.PHP

<?
$email= $_POST["email"];

$client = new
SoapClient("http://sms.dmmplatform.net/api/webservice/?wsdl");
$details[0]['email'] = "$email";
$details[0]['groups']="MYGROUP";
$json_details = json_encode($details);
$risposta = $client->addContactV2("myUsername", "myPassword", $json_details);
?>

Now I need to obtain the some result using WordPress and CF7. This is my first time with this plugin. After reading the documentation, I've tried to use the wpcf7submit event but nothing happens:

add_action( 'wp_footer', 'CF7ajaxSendToADA' );
function CF7ajaxSendToADA(){
  ?>
  <script>

  document.addEventListener( 'wpcf7submit', function( event ) {
    if ( '381' == event.detail.contactFormId ) {
        data=$('#newsletterForm').serialize();
                $.ajax({
                url: "soap.php",
                type:'POST',
                data:data,
                async:false,
                dataType:'html',
            });
    }
}, false );

  </script>
  <?php
}

Any idea?

Thank you very much for your help!!

Davide
  • 87
  • 6
  • _“Any idea?”_ - first idea: Give us a _proper_ problem description. “something went wrong” isn’t one. – misorude Aug 29 '19 at 14:02
  • @misorude Sorry: you're right! The problem is that nothing happens: CF7 does not send the email address to the SOAP service and I don't understand why... – Davide Aug 29 '19 at 14:06
  • 1
    I think doing this on the server side directly would make more sense to begin with, instead of doing your own AJAX request. https://stackoverflow.com/questions/29926252/how-to-hook-into-contact-form-7-before-send – misorude Aug 29 '19 at 14:07
  • @misorude Sorry for my late replay: your suggestion of passing values on the server side was very useful. Doing it via Ajax was only an unecessary complication. Thank you! – Davide Aug 30 '19 at 10:55

0 Answers0