Hi @kgmservizi
I hope you’re well today!
That’d be one way to do it if you can/want set the query var. Another way – without using query vars (meaning not even allowing them for the field), would be to use a code like this instead:
add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_set_custom_field_to_hidden_field', 10, 3 );
function wpmudev_set_custom_field_to_hidden_field( $entry, $module_id, $field_data_array ) {
$forms = array( 123, 3010 ); // list of forms IDs to apply it to
if ( in_array( $module_id, $forms ) ) {
foreach ( $field_data_array as $key => $value ) {
if ( strpos( $value['name'], 'hidden-' ) !== false ) {
if ( strpos( $value['value'], '{cmf_' ) !== false ) {
$cmf_name = str_replace( '{cmf_', '', $value['value'] );
$cmf_name =str_replace ( '}', '', $cmf_name );
$prep_data = Forminator_CForm_Front_Action::$prepared_data;
if ( ! empty( $prep_data['page_id'] ) ) {
$post_id = $prep_data['page_id'];
$cmf_value = get_post_meta( $post_id, $cmf_name, true );
Forminator_CForm_Front_Action::$info['field_data_array'][ $key ]['value'] = sanitize_text_field( $cmf_value );
}
}
}
}
}
}
In this line
$forms = array( 123, 3010 ); // list of forms IDs to apply it to
you need to list IDs of the forms it should work with.
Then for every hidden field that you want to have custom field value put into it you just edit such hidden field and
– set its “Default value (optional)” setting to “Custom Value” option
– and put a macro like this in the custom value
{cmf_myfield}
replacing myfield part with the name of your custom field. For example, when testing I used custom field named footnotes so I used
{cmf_footnotes}
Best regards,
Adam