Form: how to display a PDF depending on the submitted data
-
Hi all,
I have a pop form with 4 inputs and depending on one of the inputs I need to call one webservice or another. Each webservice returns a PDF file that it should be downloaded automatically after submitting the form.
I added the following function but I can’t get the PDF although all inputs are correctly parsed. I am using elementor_pro/forms/new_record
add_action( ‘elementor_pro/forms/new_record’, function( $record, $handler ) {
$form_name = $record->get_form_settings( ‘form_name’ );if ( ‘consulta_factura’ !== $form_name ) {
return;
}$raw_fields = $record->get( ‘fields’ );
$fields = [];
foreach ( $raw_fields as $id => $field ) {
$fields[ $id ] = $field[‘value’];
}$ws = ‘default url to call the webservice’;
if ($fields[ ‘tipo’ ] === ‘value1’ ) {
$ws = ‘here I have url which corresponds to value1’;
}
else {
if ($fields[ ‘tipo’ ] === ‘value2’ ) {
$ws = ‘here I have url which corresponds to value2’;
}
}// I renamed the params and fields names to post them here but they are correctly set due I added an echo sentence to check each of them
$paquete = [
‘param1’ => $fields[ ‘field_1’ ],
‘param2’ => $fields[ ‘field_2’ ],
‘param3’ => $fields[ ‘field_3’ ],
];// Is it correct to get the pdf?
wp_remote_post( $ws, [
‘body’ => $paquete,
] );
}, 10, 2 );Thanks in advance.
- The topic ‘Form: how to display a PDF depending on the submitted data’ is closed to new replies.