Saturday, 16 March 2019

send caldera form data to api

Send caldera form data to api

How to send a HTTP POST with the form data to another URL

  • Install caldera form run action add on which is free

    Then add post processor as shown in figure 

    Define action name e.g. send_data

    and put this code in function.php as given below


    add_action('send_data','send_data_function');

    function send_data_function($data)
    {

    $url = 'http://localhost/api.php';
    $myvars = array('firstname' =>$data['first_name'], //$data['slug'] change according to your form field slug
                    'lastname' => $data['last_name'],                  'email' => $data['email_address'],
                    'message' => $data['message'],
                    'commentque' => $data['comments_questions']
     );

    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_POST, 1);
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt( $ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

    curl_exec( $ch );

    }

    In this way we can post the caldera form data  to api in wordpress