You shouldn't have to add any checkbox items to your checkbox field in the form editor in order to dynamically populate it using the code example you are using. It replaces the values entirely, the existing values don't act as placeholders.
I just tested the example you are working from and implemented it on my own test site and it works fine. The example I am referring to is here:
http://www.gravityhelp.com/forums/topic/dynamic-checkboxes#post-9476
I implemented this code, exactly as is, on my test site and had no problem using it to dynamically populate the checkbox field. I am including screenshots of what I have done below.
I created a new form and on that form I placed a Checkbox field that I want to dynamically populate. The field consists of only 1 choice, but it doesn't matter as all the choices will be replaced by my custom code. See this screenshot:
http://dl.dropbox.com/u/185347/Slingshot/Pictures/Screen%20Shot%202012-04-30%20at%2011.36.52%20AM.png
After creating the form with the checkbox I then implemented the example code to populate that field dynamically using the gform_pre_render hook by placing custom code in my themes functions.php file. See this screenshot:
http://dl.dropbox.com/u/185347/Slingshot/Pictures/Screen%20Shot%202012-04-30%20at%2011.37.48%20AM.png
Now when I preview my form, the checkbox field is dynamically populated with the items it's being populated with in the custom code that I implemented as opposed to the choices in the form editor itself. See this screenshot:
http://dl.dropbox.com/u/185347/Slingshot/Pictures/Screen%20Shot%202012-04-30%20at%2011.38.25%20AM.png
So the example code does indeed work. If it's not working in your implementation that means that it wasn't implemented properly or the custom code related to getting and returning the values you want to populate the field is not functioning correctly.
I would start again from the beginning and implement the code exactly as it is found here:
http://www.gravityhelp.com/forums/topic/dynamic-checkboxes#post-9476
Then update it to suit your needs. The issue is happening on your end with how you are populating the array of choices and inputs. It sounds like if it's only passing the first value, that you aren't actually passing an array of values like you should be.
Posted 12 years ago on Monday April 30, 2012 |
Permalink