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.

pre-populate - understanding code example

  1. sascha
    Member

    Hi there,
    the original topic (http://www.gravityhelp.com/forums/topic/right-parameter-names-to-pre-populate-the-names-fields) is closed, so I started a new one to ask the question.

    I am trying to understand some code by David in the following pastie:
    http://pastie.org/1470060

    Why does he use the create_function here and not just call the function direct? Is there any reason for this?

    He uses:
    add_filter('gform_field_value_user_firstname', create_function("", '$value = populate_usermeta(\'first_name\'); return $value;' ));

    I would have used:
    add_filter('gform_field_value_user_firstname', 'populate_usermeta('first_name')');

    What are the \ before the ' for?

    Posted 12 years ago on Tuesday January 10, 2012 | Permalink
  2. The \ escapes the single quote. Otherwise there would be a syntax error.

    Not sure on WHY he did it like that, but there are always multiple ways to accomplish the same thing, and this might be one of those cases. Have you tried it by calling the function direct?

    Posted 12 years ago on Tuesday January 10, 2012 | Permalink
  3. sascha
    Member

    Ok, thought that the \ was for that. Have not called the function direct yet. Never seen the create_function used before, but it works.

    Posted 12 years ago on Tuesday January 10, 2012 | Permalink
  4. There's more than one way to do it :-)

    Posted 12 years ago on Tuesday January 10, 2012 | Permalink