• Resolved mukape

    (@mukape)


    hello,

    I need to know how to add a hidden field to the form with a custom user meta key like user_id if we need to get user id and user_last if we need to get user last name.
    is there a way to get this data using Custom value or Query parameter in hidden field ?
    Kindly check this screenshot in this screenshot we can get user id, display name, user email and user login by forminator.
    Accordingly, what to do if need to get another fields like user address, user website or user biographical info. and so on kindly see this image also

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @mukape

    I hope you are doing well today.

    It will possible only to get a user ID from a hidden field. as this one already has “User ID” option. The last name is only available in Name field set up Multiple.

    As for biographical info etc, I pinged our SLS Team to review that. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Thread Starter mukape

    (@mukape)

    I think there should be get an option to get user meta like I mentioned, maybe it’ll be dynamic or by field_name. I’m not sure
    Waiting for your reply.

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @mukape

    I hope you are doing well.

    If you are using a hidden field you can do something like:

    <?php
    add_filter('forminator_field_hidden_field_value', function ($value)
    {
    
        if (!is_user_logged_in())
        {
            return $value;
        }
    
        $user = wp_get_current_user();
    
        $user_data = get_userdata($user->ID);
    
        // To show all possible values
        //print_r($user_data);
        if (strpos($value, 'user_bio') !== false)
        {
    
            $value = $user_data->description;
            return $value;
    
        }
        elseif (strpos($value, 'user_website') !== false)
        {
    
            $value = $user_data->user_url;
            return $value;
    
        }
    
        return $value;
    
    }
    , 20, 1);
    

    Add the code as mu-plugin https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins then in the Hidden field you will select custom value and set the default value user_bio to get the Bio and user_website to get the website, but this is only an example you can extend to any other field.

    Best Regards
    Patrick Freitas

    Thread Starter mukape

    (@mukape)

    this code will not be affected by Forminator plugin update ?

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @mukape,

    A plugin update will not affect the code unless we deprecate the filter “forminator_field_hidden_field_value”, which we will mention in the plugin change log.

    Please feel free to contact us if you find the code not working so we can help you.

    Kind Regards,
    Nebu John

    Thread Starter mukape

    (@mukape)

    Thank you so much for replying.
    the code is working very well

    Regards

    Thread Starter mukape

    (@mukape)

    what if fields i need to recieve is created with acf? like mobile number?
    so, let’s say we have created and acf filed for the user fields called mobile_number, now i need to get this field in the hidden field.
    what should i do?

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @mukape

    If the field doesn’t use any ACF-specific data format, it doesn’t really matter if it was created with ACF or not. You would just need to add additional code3 block.

    For example, right below this

    elseif (strpos($value, 'user_website') !== false)
        {
    
            $value = $user_data->user_url;
            return $value;
    
        }

    add

    elseif (strpos($value, 'mobile_numer') !== false)
        {
    
            $value = $user_data->mobile_number;
            return $value;
    
        }

    and then use “mobile_number” as custom value of hidden field (just like you did so far with other fields).

    Best regards,
    Adam

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘how to add a hidden field with custom user meta’ is closed to new replies.