最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Contactform7: display results from CURL

matteradmin11PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far