0

I'm adapting the code to retrieve information from the Elementor form. I've referred to the documentation, and I have an example code snippet.

  function send_custom_webhook( $record, $handler ) {

    $form_name = $record->get_form_settings( 'form_name' );

    // Replace MY_FORM_NAME with the name you gave your form
    if ( 'MY_FORM_NAME' !== $form_name ) {
        return;
    }

    $raw_fields = $record->get( 'fields' );
    $fields = [];
    foreach ( $raw_fields as $id => $field ) {
        $fields[ $id ] = $field['value'];
    }

    wp_remote_post(
        'https://api.example.com/',
        [
            'body' => $fields,
        ]
    );
} 
add_action( 'elementor_pro/forms/new_record', 'send_custom_webhook', 10, 2 );

And here is the code from the platform that I'm attempting "Wolkvox", I've referred to the documentation, and I have an example code snippet.

    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => '',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS =>'[{
                "customer_name": "name",
                "customer_id": "customerID",
                "opt1": "tel1",
               
    
    }]',
      CURLOPT_HTTPHEADER => array(
        'wolkvox-token: '
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    
    }

The following is the output when I integrate both code samples

function send_to_external_api( $record, $handler ) {
   
    $form_name = $record->get_form_settings( 'Testing' );

  
    if ( 'Testing' !== $form_name ) {
        return;
    }


    $raw_fields = $record->get( 'fields' );
    $fields = [];
    foreach ( $raw_fields as $id => $field ) {
        $fields[ $id ] = $field['value'];
    }

   
    $data = json_encode([
        "customer_name" => $fields['name'], 
        "customer_id" => $fields['customerID'], 
        "tel1" => $fields['tel1'], 
    ]);

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => '',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => $data,
        CURLOPT_HTTPHEADER => array(
            'wolkvox-token: ',
            'Content-Type: application/json', 
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    echo $response; 
}

However, it's not sending any information to the API. Upon checking the Wolkvox platform, there doesn't appear to be any added information.

I have replaced the corresponding information in both the CURLOPT_URL and the token.

I would appreciate any guidance regarding what I might be doing wrong or why the information isn't being sent.

1
  • 1
    Is this all your code in the "wokvox sample" section above? There is no entry for the api url. Maybe you left it blank along with token for the purpose of this question? Did you try with just the sample code to see if you're actually connecting? Postman is a good tool for that. Lastly, wp_remote_post is usually used in lieu of cURL. You may need to research that feature a bit more to translate to the correct code. Are you logging your attempts? What does the error/connecting log show?
    – rudtek
    Nov 20 at 21:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.