Last active
July 15, 2020 22:32
-
-
Save felipeelia/e0b56eee9c2bc0d39d5901d5c9afed5d to your computer and use it in GitHub Desktop.
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 | |
function submit_form_data( $confirmation, $form, $entry ) { | |
... | |
/** | |
* hold the form data that will be submitted to leap API | |
*/ | |
$leap_form_data = []; | |
/** | |
* Map inputs fields | |
*/ | |
foreach ( $form['fields'] as $field ) { | |
$inputs = $field->get_entry_inputs(); | |
// phpcs:disable | |
if ( is_array( $inputs ) ) { | |
foreach ( $inputs as $input ) { | |
$value = rgar( $entry, (string) $input['id'] ); | |
if ( isset( $input['leapNameMapping'] ) && 0 !== strlen( ( trim( $value ) ) ) ) { | |
$leap_form_data[ $input['leapNameMapping'] ] = $value; | |
} | |
} | |
} else { | |
$value = rgar( $entry, (string) $field->id ); | |
if ( isset( $field->leapNameMapping ) && 0 !== strlen( ( trim( $value ) ) ) ) { | |
$leap_form_data[ $field->leapNameMapping ] = $value; | |
} | |
} | |
// phpcs:enable | |
} | |
$settings = \MicrosoftLeap\Form\Settings\get_settings(); | |
$endpoint_url = trailingslashit( $settings['api_url'] ) . 'form/submit'; | |
$response = wp_remote_post( | |
$endpoint_url, | |
[ | |
'headers' => [ | |
'Authorization' => 'Basic ' . base64_encode( $settings['http_auth_user'] . ':' . $settings['http_auth_pass'] ), | |
'Content-Type' => 'application/json', | |
], | |
'body' => wp_json_encode( $leap_form_data ), | |
] | |
); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment