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.

Using gform_field_value with a global array?

  1. tdiaz1
    Member

    I posted a similar thread, but I'll take a different approach:

    I've got various arrays available within my template, and want to put some of that data into the form being integrated into that same page:

    Viewing raw
    <?php echo $image->filename ?>
    <?php echo $iptc['location'] ?>

    So this works:

    <?php add_filter('gform_field_value_image_filename', 'get_filename'); function get_filename($value){$variable = "FileName" ;return (string) $variable; } ?>
    <?php echo $image->filename ?>
        <?php gravity_form(1, false, false, false, '', false); ?>

    This however, will not: (I get nothing)

    <?php  add_filter('gform_field_value_image_filename', 'get_filename'); function get_filename($value){$variable = $image->filename ;return (string) $variable; } ?>
    <?php echo $image->filename ?>
        <?php gravity_form(1, false, false, false, '', false); ?>

    Or simply this doesn't work. (I get nothing)

    <?php  add_filter('gform_field_value_image_filename', 'get_filename'); function get_filename($value) ; return $image->filename;  ?>
    <?php echo $image->filename ?>
        <?php gravity_form(1, false, false, false, '', false); ?>

    The instances of the plain echo work just fine. So it's available "right there".

    How do I get that information *into* the "get_filename" loop? It's obviously global.

    Otherwise, I have no clue what the purpose of this routine to pre-load data via the function is for- if all it works is with a hard coded "return "this data" because you can do that directly in Gravity Forms.

    Here is the whole page, with the Gravity Form call at the bottom:

    http://pastebin.com/b2eiNg67

    Posted 12 years ago on Friday February 3, 2012 | Permalink
  2. ironsoup
    Member

    I'm having similar frustrations...hope someone can shed some light on this topic!

    Posted 12 years ago on Thursday February 9, 2012 | Permalink
  3. Hi guys,

    This is a PHP scope issue. You need to declare that your global variable is available inside the hooked function, like so:

    [php]
    add_filter('gform_field_value_image_filename', 'get_filename');
    function get_filename($value){
        global $image;
        ...

    Now it will be available in the function per your second two examples.

    Posted 12 years ago on Thursday February 9, 2012 | Permalink

This topic has been resolved and has been closed to new replies.