PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

add filter for first name, last name

  1. i have a form that takes first name, last name, email and date.
    i am able to pre populate email and date ok, but not the first name or last name.
    can you see what is wrong with the code?
    the fields have been set to allow for dynamic updating - with first name parameter
    "firstname" and last name parameter "lastname"
    changes were made in the theme's function.php file.

    add_filter('gform_field_value_user_firstname', create_function("", '$value = populate_usermeta(\'firstname\'); return $value;' ));
    
    // populate the field with "user_lastname" as the population parameter with the "last_name" of the current user
    add_filter('gform_field_value_user_lastname', create_function("", '$value = populate_usermeta(\'lastname\'); return $value;' ));
    // populate the field with "user_email" as the population parameter with the "email" of the current user
    add_filter('gform_field_value_user_email', create_function("", '$value = populate_usermeta(\'user_email\'); return $value;' ));
    
    add_filter("gform_field_value_today", "populate_today");
    
    // this function is called by both filters and returns the requested user meta of the current user
    function populate_usermeta($meta_key){
        global $current_user;
        return $current_user->__get($meta_key);
    }
    
    function populate_today(){
    	$format = "m\/d\/Y";
    	$today_value = date($format);
    	return 	$today_value;
    	}
    Posted 12 years ago on Friday October 12, 2012 | Permalink
  2. I'm not sure about this code, but I am wondering why you cannot use the built in merge tags for the default value for these user meta values, no code required.

    Documentation: http://www.gravityhelp.com/documentation/page/Merge_Tags
    ( find {user:[meta_key]} )

    Maybe there is something unique about your situation which requires this code? It seems more complex than it needs to be.

    Posted 12 years ago on Monday October 15, 2012 | Permalink
  3. john_1
    Member

    Hi,

    I´m really trying to use the merge tags. It just doesn't work.
    I´m not sure what i´m doing wrong but have tried all kinds of different tags under "Parameter Name" for dynamical content.

    I also have read alot about adding filters to function.php etc., but this doesn't work either.

    I´d appreciate some help.

    Thanks in advance.

    /John

    Posted 11 years ago on Wednesday November 28, 2012 | Permalink
  4. David Peralty

    Hi John_1, you didn't give us much to go on. Can you explain what you are doing, and give us a step by step of what you've tried and what isn't working so we can give you some assistance?

    Posted 11 years ago on Wednesday November 28, 2012 | Permalink
  5. john_1
    Member

    David,

    Thank you for your fast reply.

    Well, I dont know how to explain everything easy.
    I want to get pre-filled form entries. In this case First name, Lastname and email.

    I have created a form with these entries and now want them to be filled in automatically depending on logged in user.
    So, I´ve gone thru all the forums trying to edit the functions.php with "add_filter" etc., since that is what they are telling me to do to populate the fields. Nothing works.

    I then came across this page with your much simpler way of doing this, by merge tags. So, I have used the tags stated on this page, http://www.gravityhelp.com/documentation/page/Merge_Tags, in the field for each form entry under tab advanced/dynamic inputs.

    Example:
    In the settings for the entry First name, I have put the tag {user:first_name}. But it doesn't work. When I bring up the form in front end the form is empty (When First name should be pre-filled with my name).

    I have tried to alter the tag in any way possible, without result.

    Any advice?

    Thanks
    John

    Posted 11 years ago on Wednesday November 28, 2012 | Permalink
  6. David Peralty

    Just ignoring pre-render functions, and focusing on the merge tags, do none of them work? Are you using separate input fields for First name and last name, or are you using the complex name field? Did e-mail work? Let me know.

    Posted 11 years ago on Wednesday November 28, 2012 | Permalink
  7. john_1
    Member

    Hi again,

    I´m using the complex name field. Non of them are working, nor does email.

    /John

    Posted 11 years ago on Monday December 3, 2012 | Permalink
  8. john_1
    Member

    Any news on this topic?

    Thank you.

    Regards
    John

    Posted 11 years ago on Saturday December 8, 2012 | Permalink
  9. john_1
    Member

    Hi again,

    Have you found any solutions that could help me with this issue?

    Happy new year,

    John

    Posted 11 years ago on Sunday December 30, 2012 | Permalink