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.

Displaying entry data in form

  1. nurunatlanta
    Member

    I need to create an Edit Form for entry data. This form needs to accessible publicly and have all the conditional logic of the Add Entry form we have created.

    I'm trying to do the following:

    1.) Pre-populate all fields from the database. I'm mimicking code from the populate drop down from entry data, which works great. But, the code that I'm using doesn't work. I think it's because I don't know what the valid key names are for the form fields. But, I could be worse off than that.

    2.) After submitting the form, delete the old entry, so only the most recently created/updated version exists.

    For #1, here is my code - it is not working & not erroring:
    http://pastie.org/1733426

    For #2, would LOVE some sample code.

    Thanks.

    Jennifer

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  2. I'll have one of our developers take a look. It might be a little bit before one of them gets a chance to respond as we are pretty busy right now with development and this is a customization.

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  3. nurunatlanta
    Member

    Thanks!

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  4. Hi Jennifer,

    Give this a go: http://pastie.org/1736308

    A couple things to note:

    1. This does not support populating all field types. It'll do single line inputs like a charm and maybe a few others, but you will probably need to add support for other field types you are using.
    2. You'll want to add a hidden field to your form that will store the original lead ID. Based on your code, I assume that your passing the original lead ID through the query string. If so, you can auto-populate this field like so: http://grab.by/9LFu
    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  5. nurunatlanta
    Member

    AWESOME!! Thanks.

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  6. nurunatlanta
    Member

    That works awesome on all the field types I need EXCEPT. Checkboxes. Here is the modification I made.... but, it doesn't work. Any ideas?

    http://pastie.org/1741091

    Thanks. Jennifer

    Posted 13 years ago on Thursday March 31, 2011 | Permalink
  7. @nurunatlanta See this forum post regarding dynamically populating checkboxes. Checkboxes are actually one of the more complex field types in Gravity Forms because they aren't really one field, each checkbox is an individual field. So they are tricky to work with from a dynamic population standpoint. Here is the post:

    http://www.gravityhelp.com/forums/topic/dynamically-populate-checkboxes

    Posted 13 years ago on Thursday March 31, 2011 | Permalink
  8. nurunatlanta
    Member

    Hmmm... can't figure out how that works??? I'm doing a database hit and pulling all the field data for the entry and through php code setting the values.

    I'm trying to reference the checkboxes in the following way...

    foreach($form['fields'] as &$field){
    
    		        if(!isset($entry[$field['id']]))
    		            continue;
    
    			//NOTE: defaultValue works to set Text, TextArea, RadioButton, Date and Select Fields
    				if ($field['type'] != 'checkbox') {
    		        	$field['defaultValue'] = $entry[$field['id']];
    				} else {
    					//handle checkbox
    					foreach($field['choices'] as $choice) {
    						if ($choice['text'] == $entry[$field['id']]) {
    							$choice['isSelected'] = "checked='checked'";
    						}
    					}
    				}
    
    		    }

    Will something like this NOT work?

    Jennifer

    Posted 13 years ago on Friday April 1, 2011 | Permalink
  9. Hi Jennifer,

    Replace the old snippet with this one: http://pastie.org/1744975

    Posted 13 years ago on Friday April 1, 2011 | Permalink
  10. This is very similar functionality to what I need to add, Can you give me a sense of how and where you are then calling your functions?

    I added the code from the pastebin into my functions.php file, however if I try to access a page such as http://www.mysite.com/edit-directory/?lid=12, it just loads an empty form.

    Thanks,
    brian

    Posted 13 years ago on Tuesday April 5, 2011 | Permalink
  11. I've got this working on my end and trying to expand it. Thanks for the code so far. Any word on this making a future build? I'm trying to customize the function to reach into "address" and "name" types as well. I'd be happy to pay for this rather than dabble. Contact me if I can contract this work/feature.

    Posted 13 years ago on Tuesday April 19, 2011 | Permalink
  12. radioswan
    Member

    This is also similar to the type of functionality i need. Any chance someone could detail the steps required to get this working? I've added the hidden field to my form that will store the original lead ID.

    Where should the function code be placed? Any other steps required?

    Thanks.

    Posted 12 years ago on Thursday April 28, 2011 | Permalink
  13. Any customizations using hooks/filters would normally go in your themes functions.php file. The alternative is to write your own custom plugin with the code in place in the plugin and then activate the plugin, but that is more advanced. Most people put them in the functions.php file of their theme.

    Posted 12 years ago on Thursday April 28, 2011 | Permalink
  14. We have this working for the most part but when setting the value, for example:

    $field['value'] = 'test';
    print_r($field['value']);

    I get "test" as the value but it doesn't show it in the rendered form.

    Posted 12 years ago on Friday April 29, 2011 | Permalink
  15. We'd have to see all of your code to see what you are doing, that snippet isn't enough to go on because we don't know what you are trying to do. I suggest posting more of the code snippet to http://pastie.org and then describe what you are trying to do and include a link to your code on http://pastie.org so we can take a look.

    Posted 12 years ago on Friday April 29, 2011 | Permalink
  16. Thanks Carl. I have the following based on the samples earlier in this thread, in functions.php.
    <script src='http://pastie.org/1849344.js'></script>

    I see the values coming out of $entries properly but I can't seem to assign the value as the default value to the fields before rendering the form. I'm trying to pre-populate the form from a lead so that it's already pre-populated with data we already have at form render time. Thank you!

    Posted 12 years ago on Saturday April 30, 2011 | Permalink
  17. Oops, can't edit that last post, pastie: http://pastie.org/1849344

    Posted 12 years ago on Saturday April 30, 2011 | Permalink
  18. To dynamically populate a field using PHP you need to set that field so it can be dynamically populated (edit the field, select advanced tab, check the "allow field to be populated dynamically" checkbox and give it a unique parameter name). You then use this parameter name with the gform_field_value hook to populate it dynamically.

    The hook you use is documented here:

    http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    Posted 12 years ago on Monday May 2, 2011 | Permalink
  19. radioswan
    Member

    Did anyone have any luck with this? It's a bit beyond my skillset unfortunately, it would be great if a plugin was available as I would be willing to pay for this feature.

    Posted 12 years ago on Tuesday May 10, 2011 | Permalink
  20. Hi,
    I have very similar problem. I want to prepopulate a form with data I've pulled back from the database. This works fine except the final rendering.
    The problem is that the form does not show the populated data.
    In the pre-render function, I assign values and these seem to be fine - I used echo statements to verify this.
    I simplified the problem so that if I do a direct string assignment to a text field :-
    $form["fields"][ID_NAME]['defaultValue'] = "hello there !" ;
    ... nothing appears on the rendered form in the field indexed by ID_NAME.

    Any ideas ? Am I doing something silly ?

    Posted 12 years ago on Friday November 4, 2011 | Permalink
  21. I've gotten this working for a form so that I can restore a form and allow the user to edit it using the lead_id as a parameter in the URL. My form has multiple pages, however, and I'd like to allow the user to save it on any page, as opposed to just the final page.

    The method suggested above deletes the previous lead, rather than simply updating it. Why? How would one update the original lead instead - in order to maintain the same lead ID?

    I want to do this so that I can add in auto-save functionality on a regular interval and/or add a button to each page of the form to "save" the data to the db. With the delete method, every time a user would try to save, the url parameter would need to be updated to the new lead id and I'd be needlessly destroying and creating db records.

    Also, it has been suggested in the past on this forum, to implement auto-save functionality by saving the data in a cookie on the users computer via a jQuery plugin. I don't want to do it this way for various reasons - mostly shared computers/user accounts and sensitive data, but also multiple computers, different locations, etc.

    Any suggestions on how to tackle this one?

    Posted 12 years ago on Friday December 23, 2011 | Permalink
  22. sascha
    Member

    Listening in...

    Posted 12 years ago on Sunday January 15, 2012 | Permalink
  23. schnettker
    Member

    I have the same problem like Jennifer but the code snippet http://pastie.org/1744975 is offline. Can you upload it on pastebin please?

    Posted 11 years ago on Monday April 30, 2012 | Permalink