• Hi,
    I want to store the collected data to Google Spreadsheet.

    My plan is to a add a webhook post (with function.php) to IFTTT and do there the rest.

    But with Multiform the process is hanging at the first form and its not proceeding to Form2.

    Here is my funtion.php code:

    	
     // Create the new wordpress action hook before sending the email from CF7
    add_action( 'wpcf7_before_send_mail', 'my_conversion' );
       function my_conversion( $contact_form ) {
       $submission = WPCF7_Submission::get_instance();
      
      // Get the post data and other post meta values
    if ( $submission ) {
        $posted_data = $submission->get_posted_data();
        $remote_ip = $submission->get_meta( 'remote_ip' );
        $url = $submission->get_meta( 'url' );
        $timestamp = gmdate("Y-m-d H:i:s", $submission->get_meta( 'timestamp' ));
        $title = wpcf7_special_mail_tag( '', '_post_title', '' );
        
      // If you have checkboxes or other multi-select fields, make sure you convert the values to a string  
        $mycheckbox1 = implode(", ", $posted_data["checkbox-JA"]);
       // $mycheckbox2 = implode(", ", $posted_data["checkbox-466"]);
     
      // Exclude any email addresses (eg: email addresses you use to test forms)
    if ( !in_array($posted_data["your-email"], array('[email protected]','[email protected]','[email protected]'), true ) ) { 
      
      // Split the first and last names
        if ($posted_data["your-name"]){
        $name = trim($posted_data["your-name"]);
        $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name);
        $first_name = trim( preg_replace('#'.$last_name.'#', '', $name ) );
      
      // Set default value for last name if none is provided   
          if ($last_name == NULL ){
          $last_name = "Not Provided";
          }
        }
     
      // Encode the data in a new array in JSON format
      $data = json_encode(array(
          
    	  "{{Vorname}}" => "{$posted_data["Vorname"]}",
    	  "{{Nachname}}"=> "{$posted_data["Nachname"]}",
    	  "email" => "{$posted_data["your-email"]}",
    	  "{{Adresse}}"=> "{$posted_data["Adresse"]}",
    	  "{{PLZ}}"=> "{$posted_data["PLZ"]}",
    	  "{{Wohnort}}"=> "{$posted_data["Wohnort"]}",
    	  "{{Bundesland}}"=> "{$posted_data["Bundesland"]}",
    	  "{{Land}}"=> "{$posted_data["Land"]}",
    	  "{{Datum}}"=> "{$posted_data["Datum"]}",
    	  "{{Onlinevertrag}}"=> "{$posted_data["JA"]}",
    	  "{{IBAN}}"=> "{$posted_data["IBAN"]}",
    	  "{{BIC}}"=> "{$posted_data["BIC"]}",
    	  "email" => "{$posted_data["your-email"]}",
          "{{TrackingInfo}}"=> "{$posted_data["tracking-info"]}",     
    	  "{{id}}" => "{$posted_data["submit_time"]}",
          "{{Submitted}}" => "$timestamp",
    	  "{{From URL}}" => "$url",
          "{{From Referer}}" => "{$posted_data["referer-page"]}",
    	  "{{From IP}}" => "$remote_ip",
          "{{Page Title}}" => "$title"
    	 // "first-name" => "$first_name",
         // "last-name" => "$last_name",
         //"full-name" => "{$posted_data["your-name"]}",
         // "phone" => "{$posted_data["tel-212"]}",
         //"checkbox1" => "$mycheckbox1",
          
          ));
     
       // Finally send the data to IFTTT or your other webhook endpoint
            $ch = curl_init("https://maker.ifttt.com/use/XXXXXXXXXXXXXXXX"); // replace with your IFTTT webhook
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,5); //Optional timeout value
            curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Optional timeout value
            $result = curl_exec($ch);
            curl_close($ch);
            
        return $result;
          }
        }
      }

    Cheers

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ricksterzh

    (@ricksterzh)

    I see the function.php would send the code from the first step.

    So I will need a code to execute this code at the last step of the form.

    Any suggestions?

    Cheers!

    Plugin Author webheadcoder

    (@webheadllc)

    You can try the wpcf7_posted_data filter in the Contact Form 7 plugin to access the submitted form data.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Webhook with Multistepform’ is closed to new replies.