• Resolved katmacau

    (@katmacau)


    Hello. I am trying to work out how to get the name fields or other input fields to show user meta. Eg if a user if logged in I want the first name field to populate with their first name, the email with their email etc. Do you offer this option?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @katmacau

    I hope you are doing good today.

    You can set the pre-fill for some of your fields and then use this custom snippet code to auto-fill them:

    add_filter( 'forminator_cform_render_fields', function( $wrappers, $form_id ){
    	if( $form_id === 123 && is_user_logged_in() ){
    		$current_user = wp_get_current_user();
    		$_REQUEST['user-login'] = $current_user->user_login;
    		$_REQUEST['user-email'] = $current_user->user_email;
    		$_REQUEST['user-firstname'] = $current_user->user_firstname;
    		$_REQUEST['display-name'] = $current_user->display_name;
    	}//End check form id.
    	return $wrappers;
    }, 10, 2 );

    where 123 is an ID of your form.

    You can add the above snippet as a mu-plugin on your site:

    Must Use Plugins

    Kind Regards,
    Kris

    Thread Starter katmacau

    (@katmacau)

    Excellent. Thanks for that! Will give it a try.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Show user meta in fields’ is closed to new replies.