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.

Dynamically loaded options in select box disappearing in multi-page forms

  1. Hey guys,

    We're currently hitting a bit of a problem with may be some built in GravityForms data validation code biting us in the rear. Hoping you'll know ...

    In short, what we're doing when building a form is adding a class name to a certain field that we're using (via the built in hook) and populating that dropdown's value all ajaxy-ish based on the selection from a previous dropdown, like so:

    <script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function($){
    	$('li.rw_school_dropdown select').change(function(){
    		$.ajax({
    			url		:	'<?php bloginfo('url'); ?>',
    			data	:	{
    				action		:	'get_degrees_options_from_school_id',
    				school_id	:	$(this).val()
    			},
    			dataType:	'text',
    			success	:	function( data ){
    					console.log( data );
    					$('li.rw_degree_dropdown select').html( data );
    				}
    		});
    	});
    });
    </script>

    and it's working great! The second field gets populated properly, and on single-page forms the data we're catching at gform_post_submission is good, and the field has the proper value from the dynamically loaded dropdown.

    However, on multi-page forms, with the dropdowns on page 1 the form, it seems that the value doesn't get carried across to the gform_post_submission hook ... my first guess is that you guys may be running some sort of data validation, making sure that the option selected by the dropdown select box matches one of those available for the form in the DB? As we're populating it dynamically from an alternate data source, of course it's not going to match, and therefore gets filtered out?

    Is there any way that we can get the data we want? Do you have any idea why it's getting snagged away?

    Posted 13 years ago on Sunday March 27, 2011 | Permalink
  2. You are exactly right. There is logic in place to make sure the values in the drop down select box matches those in the database. This is for security reasons so that users can't manipulate the selection values.

    There is, however, a way around this. I am forwarding this post to one of our developers who will respond with some information on how to accomplish what you want to do without running into the data validation issue.

    Posted 13 years ago on Sunday March 27, 2011 | Permalink
  3. Thanks!

    On the off chance, we're currently using the gform_post_submission hook ... to just get a snapshot of the data, would the gform_pre_submission hook happen to have the raw data, or -- as it was on a previous page of a multipage form -- would that not work either?

    Looking forward to hearing what the developer thinks!

    Thanks!

    Posted 13 years ago on Sunday March 27, 2011 | Permalink
  4. gform_post_submission is the right hook to get a snapshot of the data. Your problem is that you are populating the second drop down only when the first drop down changes. When the page refreshes when going to the second page, your changes are gone.
    If your form is an AJAX form, you can use the gform_page_loaded javascript hook (http://www.gravityhelp.com/documentation/page/Gform_page_loaded) to re-populate your drop down everytime the page changes.
    If your form is not an AJAX form, you will need to use the gform_pre_render php filter (http://www.gravityhelp.com/documentation/page/Gform_pre_render) in order to add those drop down values when going from one page to the next.

    I hope this helps!
    Alex.

    Posted 13 years ago on Monday March 28, 2011 | Permalink
  5. @randomwalk Did you guys ever figure this issue out? We're also using AJAX to populate dropdowns based on user selections in a multi-page form and the data is being lost in subsequent pages. Any help would be greatly appreciated, I've been working on it for hours and I'm stumped!

    Posted 12 years ago on Tuesday January 10, 2012 | Permalink

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