Forked from csalzano/elementor-form-additional-webhook.php
Created
February 12, 2019 12:40
-
-
Save deckerweb/2896fd232ca4cb4abc8149ebdaa87293 to your computer and use it in GitHub Desktop.
Elementor Form additional webhook example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Elementor Form Additional Webhook | |
* Plugin URI: https://coreysalzano.com/ | |
* Description: Adds a second Webhook to the Lot Wizard trial signup form | |
* Version: 1.0.0 | |
* Author: Corey Salzano | |
* Author URI: https://github.com/mistercorey | |
* License: GPLv2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
class Elementor_Form_Additional_Webhook { | |
function hooks(){ | |
//Add our additional webhook right here | |
add_action( 'elementor_pro/forms/new_record', array( $this, 'manipulate_form_submission' ), 10, 2 ); | |
} | |
function manipulate_form_submission( $record, $ajax_handler ) { | |
$form_data = $record->get_formatted_data(); | |
//change the names of fields before we send them somewhere | |
$new_data = array( | |
'First_Name' => isset( $form_data['First Name'] ) ? $form_data['First Name'] : '', | |
'Last_Name' => isset( $form_data['Last Name'] ) ? $form_data['Last Name'] : '', | |
'URL' => isset( $form_data['Website'] ) ? $form_data['Website'] : '', | |
); | |
$response = wp_remote_post( 'http://api.somewhere.com/', array( 'body' => $new_data ) ); | |
//if the failure of our additional webhook should prevent the form from submitting... | |
if( is_wp_error( $response ) ) { | |
$msg = 'There was a problem launching the rocket. Please check with mission control.'; | |
$ajax_handler->add_error( $field['id'], $msg ); | |
$ajax_handler->add_error_message( $msg ); | |
$ajax_handler->is_success = false; | |
} | |
} | |
} | |
$elementor_webhook_239909870234 = new Elementor_Form_Additional_Webhook(); | |
$elementor_webhook_239909870234->hooks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! It helps a lot.