Code I used on websquadronapi.local which is where WP Forms and WordPress are installed
function wpf_george_process_complete( $fields, $entry, $form_data, $entry_id ) {
// Optional, you can limit to specific forms. Below, we restrict output to
// form #5.
if ( absint( $form_data['id'] ) !== 5 ) {
return;
}
// Get the full entry object
$entry = wpforms()->entry->get( $entry_id );
// Fields are in JSON, so we decode to an array
$entry_fields = json_decode( $entry->fields, true );
// get the first name and email as a string
$FullName = $entry_fields['1']['value'];
$Email = $entry_fields['2']['value'];
// Convert back to json
$entry_fields = json_encode( $entry_fields );
// Save changes
wpforms()->entry->update( $entry_id, array( 'fields' => $entry_fields ), '', '', array( 'cap' => false ) );
//magic time start if( ! $FullName || ! $Email ){
error_log( 'Unable to get userdata!' );
return;
}
$body = array(
'FullName' => $FullName,
'Email' => $Email
);
$url = 'https://georgiosn39.sg-host.com/savedata.php?FullName='.$FullName.'&Email='.$Email;
$args = array(
'method' => 'POST',
'timeout' => 45,
'sslverify' => false,
'headers' => array(
//'Authorization' => 'Bearer {token goes here}',
'Content-Type' => 'application/json',
),
'body' => $body,
);
$request = wp_remote_post( $url, $args );
if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) != 200 ) {
error_log( print_r( $request, true ) );
}
$response = wp_remote_retrieve_body( $request );
//console_log($response);
//magic time end
}
add_action( 'wpforms_process_complete', 'wpf_george_process_complete', 10, 4 );
0 Comments