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.

Hidden Field values not writing to database

  1. vixvii
    Member

    I have a couple of hidden fields on my form that gets dynamically populated. If I do a

    echo "<h1>Team : " .$_POST["input_8"] ."</h1>";

    I get the correct value returned, but when I press the submit button this value is not written to the database, only the 3 visible fields' data is entered into the database. It isn't even making a entry for the field in the database...

    Any ideas?

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  2. I don't know how you are populating the fields dynamically. If they aren't showing up, they aren't being populated. I'm assuming you are populating these hidden fields dynamically. Make sure you are doing it correctly. Here is a tutorial:

    http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  3. vixvii
    Member

    Carl, I might be doing something wrong, but I am populating them the same way I use for other forms that are working. Maybe not the best way? I had a look at the tutorial, but not 100% clear on it... Will I need to write a hook for every field I populate?

    Here's my code : http://www.pastie.org/2418836

    I populate them on line 43 and 44

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  4. If you are populating standard fields (read: not checkbox or drop down but standard inputs) dynamically you should be doing it using this method:

    http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population

    Not via the pre render hook.

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  5. vixvii
    Member

    Thanks once again Carl - I think I am clearly missing something and my hacking skills are failing me...

    This is what I have :

    add_filter('gform_field_value_your_parameter', 'my_custom_population_function');
    function my_custom_population_function($value){
        //return 'boom!';
    	return $value;
    }
    
    add_filter("gform_pre_render_16", populate_comp_dropdown);
    function populate_comp_dropdown($form){
    
    $unique_id = "WP11003";
    my_custom_population_function($unique_id);
    return $form;
    }

    If I swap the comment marks and run return 'boom!'; in the function it works, but passing a value doesn't. Also, if I add a echo $value; just before the return, I do get the correct value displayed. Am I misunderstanding this?

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  6. vixvii
    Member

    Just to update... When I use this with the above code :

    add_filter('gform_field_value_your_parameter', 'my_custom_population_function');
    function my_custom_population_function($value){
        echo $value;
    	$test = 'WC11006';
    	return $test;
    	//return $value;
    }

    The value WP11003 is echoed and the field is populated with WC11006 - so it "works". But if I add $test = $value; or return $value directly it doesn't work at all. Must I convert $value to a certain type?

    Posted 13 years ago on Wednesday August 24, 2011 | Permalink
  7. vixvii can you post your actual code to pastie.org or pastebin.com and explain what should be happening, and what is actually happening? Looking at these edited copies has me confused and there are a couple syntax errors in there that might just be from editing to display them here.

    Please post the actual functions.php. Thanks

    Posted 13 years ago on Thursday August 25, 2011 | Permalink
  8. vixvii
    Member

    Chris, Thanks for looking into this and please feel free to point out ANY syntax errors. I have been thrown in the deep end here and I am learning my way through php :-)

    My code : http://www.pastie.org/2429277

    Basically I am getting values from the database and populating a drop down list (which is working) Then I have two hidden fields for unique ID and for the team name. For now I was just focussing on the Unique ID.

    lines 60 - 63 returns the correct values, so I know my variables are working.
    lines 161 - 165 is the function I am using at the moment to see if I could get it to work. And basically if I put in there $value = 'boom!' then it works and the value is dynamically placed in the text box.

    I can even echo the value passed to that function and get the correct value returned. But as soon as I use the uniqueID in the return statement, the value does not get passed to the form. It is VERY strange... I can give you full access to this server if it will help, just let me know where I must mail the details.

    Thanks again! I owe you guys A LOT!

    The site is topweddingphotos.com (developmet server)

    Posted 13 years ago on Thursday August 25, 2011 | Permalink
  9. vixvii
    Member

    Trust you are all safe...

    Just a quick update. After a lot of struggling I added a pre_submission_handler function and I just used $_POST["input_11"] = $uniqueID;

    This works! I know this is not the correct way to dynamicaly populate a field, but it's the only way that works.

    Posted 13 years ago on Monday August 29, 2011 | Permalink
  10. Glad you got it working. Thanks for the update.

    Posted 13 years ago on Tuesday August 30, 2011 | Permalink

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