edit user input data contact form 7
I have created a form that posts user input to an API, in my function I have multiple Posted Data entries that take the value from my user input. In my $body variable I have set it to receive the API response after my API is sent, but now I want this response to be shown in my user inputs $body = $posted_data['dynamichidden-458'];
- I have $body that receives the API response
- in $body = $posted_data['dynamichidden-458']; I want my API response to take over the value of the dynamichidden-458 field.
- I want it like this so that when viewing the user inputs via a DOM listener I can capture the values of my users along with their API response.
My Question How do I set the value of Dynamichidden-458 to my $body API response.
function Kiri_cf7_api_sender( $contact_form ) {
if ( $contact_form-title === 'Quote_form' ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission-get_posted_data();
$name = $posted_data['your-name'];
$surname = $posted_data['your-name2'];
$phone = $posted_data['tel-922'];
$urltest = $posted_data['dynamichidden-739'];
$posted_data['dynamichidden-458'] = $body;
if ( strpos( $urltest, '?phone' ) !== false ) {
$url = 'api string';
} elseif ( strpos( $urltest, '?email' ) !== false ) {
$url = 'api string';
} else {
$url = 'api string';
$response = wp_remote_post( $url );
$body = wp_remote_retrieve_body( $response );
ob_start(); // start buffer capture
var_dump( $name );
var_dump( $surname );
var_dump( $phone );
var_dump( $url );
var_dump( $urltest );
var_dump( $body );
$contents = ob_get_contents(); // put the buffer into a variable
ob_end_clean(); // end capture
error_log( $contents );
return;
print_r( $submission );
}
}
}
}```
Topic plugin-contact-form-7 ajax variables Wordpress
Category Web