Hi @jemo97,
I hope you are doing well today!
The following code snippet could be used as a mu-plugin to help you on the issue.
<?php
add_action('wp_footer', 'wpmudev_change_hidden_val', 9999);
function wpmudev_change_hidden_val() {
if ( ! is_page( 'your_page_slug' ) ) { //Please use your page slug
return;
}
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$( '#radio-1 input' ).on( 'change', function() {
var radio_val = $(this).val();
$('input[name="hidden-1"]').val(radio_val);
});
});
</script>
<?php
}
add_filter( 'forminator_prepared_data', 'wpmudev_add_hidden_field_val', 10, 2 );
function wpmudev_add_hidden_field_val( $prepared_data, $module_object ){
if ( $module_object->id != 6 ) { //Please change the form ID
return $prepared_data;
}
if ( empty( $prepared_data['hidden-1'] ) ) {
$prepared_data['hidden-1'] = sanitize_text_field( $_POST['hidden-1'] );
}
return $prepared_data;
}
add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_change_hidden_field_data', 10, 3 );
function wpmudev_change_hidden_field_data( $entry, $module_id, $field_data_array ) {
$form_ids = array(6); //Please change the form ID
if ( ! in_array( $module_id, $form_ids ) ) {
return;
}
foreach ( $field_data_array as $key => $value ) {
if ( strpos( $value['name'], 'hidden-1' ) !== false ) {
Forminator_CForm_Front_Action::$info['field_data_array'][$key]['value'] = sanitize_text_field( $_POST[$value['name']] );
}
}
}
A few notes on the code snippet;
your_page_slug
?should be replaced with your page slug
6
?should be replaced with your form’s ID
radio-1
?should be changed to radio field ID
hidden-1
?should be changed to hidden field’s ID.
You can find more information below on how to use mu-plugins.
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
and
https://www.ads-software.com/support/article/must-use-plugins/
Kind regards,
Zafer