php - Contactform7: display results from CURL

admin2025-06-02  3

I am stuck into a problem.

I sent contact form data through curl and I get a response from an API. How is it possible to display there results on my page? Ideally through AJAX and in my own custom div ?

add_action('wpcf7_mail_sent', function ($contact_form) { // Run code after the email has been sent 
  $title = $contact_form->title;
    $submission = WPCF7_Submission::get_instance();

    if ( $submission ) {
        $posted_data = $submission->get_posted_data();

        if ($posted_data['type'] == 'var1')
        {

            APIcurl(.....);

        }

    }

});

function APIcurl($var...)
{
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL =>  'https [...]

$response = curl_exec($curl);

How to show the response on my page ? I tried this but it was not successfull : document.addEventListener( 'wpcf7mailsent', function( event ) { alert(''); alert('test'); }, false ); }

Many thanks in advance

EDIT : maybe is the solution to add an "add_action" after the API function such as : add_action('wp_footer'... but I don't know how I can display the results of the API function in this.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748877204a314463.html

最新回复(0)