Random number/string in hidden field

[ad_1]

Hi @graphixz

I hope you are doing well today.

I pinged our SLS Team to review your query and see what will be possible in this case. We will post an update here as soon as more information is available.

Kind Regards,
Kris

Hi again @graphixz

Please us this snippet as a mu-plugin:

add_filter( 'forminator_prepared_data', 'wpmudev_random_user_hidden_field', 10, 2 );
function wpmudev_random_user_hidden_field( $prepared_data, $module_object ){
	if ( 1771 != $module_object->id ) { // Please change the form ID.
		return $prepared_data;
	}

    foreach ( $prepared_data as $key => $value ) {
        if ( '{random_user}' == $value ) {
            $prepared_data[$key] = 'USR' . random_int( 100000, 999999 );
        }
    }
	return $prepared_data;
}

add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_user_hidden_field_data', 10, 3 );
function wpmudev_user_hidden_field_data( $entry, $module_id, $field_data_array ) {
    $form_ids = array( 1771 ); // Please change the form ID.
	if ( ! in_array( $module_id, $form_ids ) ) {
		return;
	}
    
    foreach ( $field_data_array as $key => $value ) {
        if ( '{random_user}' == $value['value'] ) {
            Forminator_CForm_Front_Action::$info['field_data_array'][$key]['value'] = sanitize_text_field( Forminator_CForm_Front_Action::$prepared_data[ $value['name'] ] );
        }
    }
}

Please change 1771 to your form ID twice in above code. In your hidden field please use Custom Value and type “{random_user}”.

To learn more about how to install MU-Plugin to a site, please, check this out: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

Kind Regards,
Kris

Thanks Kris, I will try this as soon as possible!

Hello @wpmudevsupport13
I just implemented this and it looks like it’s working perfectly!
Thanks for the awesome fast response.
Have a great day!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer