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.

Trouble with Gform field value $parameter name

  1. Perhaps
    Member

    Greetings, Unfortunately im not that great with PHP and my searching has yielded nothing. I am trying to "dynamically" fill in a field using the "Gform field value $parameter name". It works fine except I'd like to use a php variable (? i think it would be called that) e.g.

    <?php
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
    	$testyo = "blah";
       	return $testyo;
    }

    The above works.

    <?php
    $testyo = $client_email;
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
       	return $testyo;
    }

    But the above won't work. The $client_email is something that's defined further up. I'm sure the solution is simple and I'd appreciate any help. Forgive my ignorance.

    Posted 14 years ago on Wednesday May 25, 2011 | Permalink
  2. Try this:

    <?php
    $testyo = $client_email;
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
        global $testyo;
        return $testyo;
    }
    Posted 14 years ago on Wednesday May 25, 2011 | Permalink
  3. Perhaps
    Member

    Hello David. I appreciate the help. Your solution works. I am just having a little difficulty tying the funtions.php file with the page template file. I realise this falls out of the gravity forms scope and more into the general php help... but if you can help anyway it will be appriciated :)

    Placing the below in the function.php file works.

    <?php
    $client_email = "lol";
    $testyo = $client_email;
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
        global $testyo;
        return $testyo;
    }

    However $client_email is defined in the page template file (as this differs on a page by page basis). I tried the below in the functions.php file

    <?php add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
        global $value;
        return $value;
    }

    and the below in the page template file

    <php
    populate_email($client_email);

    But that didn't seem to work. I probably don't understand the correct usage. I'm just playing a guessing game at the moment.

    Posted 14 years ago on Thursday May 26, 2011 | Permalink
  4. If you declare this variable anywhere above the form in your page template:

    [php]
    $client_email = "test@test.com";

    ...and then leave the following in your functions.php, it should do the trick.

    [php]
    add_filter("gform_field_value_email", "populate_email");
    function populate_email($value){
        global $client_email;
        return $client_email;
    }

    Since the gform_field_value_XX filter runs after we've declared our $client_email, the populate email filter should get the updated value based on the page.

    Let me know how it goes.

    Posted 14 years ago on Thursday May 26, 2011 | Permalink
  5. Perhaps
    Member

    Hi David, I'm sorry it took so long to reply I was on holiday without a computer. Your code works if..

    $client_email = "test@test.com";

    is placed in the functions.php file. But it stops working as soon as I place it in the page template. Its weird, because I can echo $client_email and it shows fine, its just not connecting with gravity forms.

    Posted 14 years ago on Monday June 6, 2011 | Permalink
  6. Could you create a pastie with your page template code?

    Posted 14 years ago on Monday June 6, 2011 | Permalink
  7. Perhaps
    Member

    I found the problem. I don't know if you are familiar with the Pods plugin. Anyway, your lovely code worked fine on a normal Wordpress page template. But moving the same page template to the pods page caused the $client_email not to show. Its weird because if I put $client_email = "test@test.com"; in the functions file, it works fine. Its just if I try to declare $client_email = "test@test.com"; in the page template file that doesn't work. It must be to do with the way pods executes pages that isn't reading something.

    Anyway thanks for your help. I really appreciate it.

    Posted 14 years ago on Tuesday June 7, 2011 | Permalink