• Resolved Agencia 221B

    (@agencia221b)


    Hi guys.

    I see the option in hidden field for bring the email of the user filling the form. But I really need another hidden field to bring the first name, last name and nickname of the user.

    Is that possible?

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Imran – WPMU DEV Support

    (@wpmudev-support9)

    Hi @agencia221b,

    Thank you for contacting us.

    This option is currently not possible with the current values set for the hidden field. I have forwarded this to our Plugin Team to verify if this is possible with some custom code. We will get back to you with an update.

    Best,
    Jonathan S

    Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hey there @agencia221b, Jorge here.

    We got a reply from our colleagues with a small snippet to help you accomplish this.

    Just create a mu-plugin with the following code:

    <?php
    add_filter(
    	'forminator_field_hidden_field_value', 
    	function( $value, $saved_value, $field ) {
    		if ( is_user_logged_in() ) {
    			$current_user = wp_get_current_user();
    			$replacements = array(
    				'USER_FIRST_NAME' => $current_user->user_firstname,
    				'USER_LAST_NAME'  => $current_user->user_lastname,
    				'USER_NICKNAME'   => get_user_meta( $current_user->ID, 'nickname', true ),
    			);
    			$value = str_replace( array_keys( $replacements ), array_values( $replacements ), $value );
    		}
    		return $value;
    	},
    	20,
    	3
    );

    You would need to add 3 hidden fields in form, edit them and set “Custom Value” as Default Value. For firstname insert USER_FIRST_NAME , for last name insert USER_LAST_NAME and or nickname add USER_NICKNAME. Those should be replaced with the according values.

    You need to save this file on wp-content/mu-plugins

    Hope this helps, and feel free to reach out if you have any further questions.

    Regards,

    Jorge

    Thread Starter Agencia 221B

    (@agencia221b)

    Hey guys, thank you so much for this solution.

    I’m a little busy right now with other projects, so I am unable to test it, but as soon as I can I’ll test the code and tell you if it worked.

    Regards

    Plugin Support Imran – WPMU DEV Support

    (@wpmudev-support9)

    Hi @agencia221b,

    We are glad to assist. I will be marking this ticket as resolved for now, but feel free to follow up in case you have any additional questions.

    Best,
    Jonathan S

    Thread Starter Agencia 221B

    (@agencia221b)

    Hey guys, just tested the code right now and everything worked flawlessly.

    Thank you so much.

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to hidden field bring logged in user’s name and nickname’ is closed to new replies.