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.

Using User Registration Dynamic Drop Downs, capture one value from multiple list

  1. Hi. First off, let me say I am not an experienced php guy. So, now that you know I am "challenged" when it comes to this kind of stuff, here's what I'm trying to do.

    Building a user registration form to capture user location data - so, say, Country, Province/State and City. All of that data is driven by drop downs - with conditional logic dictating which forms should show or not. As an example, if I select COuntry: Canada, only Canadian provinces pop up. Then if I select Province Alberta, only cities from Alberta show up. That is done and works fine. Now what I am trying to do is capture the information from the city field so I can pass it along to the user city field.

    The reason this is hard is because I have over 70 different lists that are conditionally going to appear based on previous selections. So how do I merge the values from these 70 lists into one value? I've tried making a hidden field with merge values but can't get those to work. Would a function adding up the value of all of the fields work? I have been working on this for 5 hours and my head is ready to explode. Any help would be much appreciated.

    Posted 11 years ago on Friday December 7, 2012 | Permalink
  2. Can you share a link to what you have online right now, so we can see how far you have gotten?

    Posted 11 years ago on Monday December 10, 2012 | Permalink
  3. Sure I'll post a sample. Haven't activated the user registration form yet because I am trying to figure this part out. Essentially trying to take my 70 fields and merge them into 3. Country, Province and City. Instead of the existing conditionally driven logic fields Country, Province, State, City AB, City BC, City SK e.t.c.......

    So what I think I want to do is create one hidden field for province or state - meaning that there is ONE field I can use that takes the value from the conditional Province Or State fields - and the same for city.

    Posted 11 years ago on Monday December 10, 2012 | Permalink
  4. Well I can't seem to get the registration form to post to my site. I'm using "Buddyboss" as a theme and it looks like the "registration.php" for buddyboss is preventing my gravity form from turning up.

    So I've posted it to another page. (http://sunasocial.com/test-for-form/)

    I'll post a seperate topic for the buddyboss registration issue.

    Posted 11 years ago on Monday December 10, 2012 | Permalink
  5. I see your form online now and I see how it works. Can you export the form that provides that functionality and email it to me at chris@rocketgenius.com please?

    The form export is under Forms > Import/Export > then the top center menu item "Export Forms". When done correctly you will have a file with an XML extension. Please attach that to an email and send it to chris@rocketgenius.com - thank you.

    Posted 11 years ago on Tuesday December 11, 2012 | Permalink
  6. Hi I did, but you haven't replied to me yet. Just want to make sure you got the e-mail, and that the exported form was OK. You did mention that you weren't sure which topic it was for, but I emailed you the info. Can you confirm that you have everything you need? Thanks!

    Posted 11 years ago on Wednesday December 19, 2012 | Permalink
  7. I've put all the pieces together now. I have your email associated with this topic and will take a look at it today.

    Posted 11 years ago on Thursday December 20, 2012 | Permalink
  8. Thanks!

    Posted 11 years ago on Thursday December 20, 2012 | Permalink
  9. It sounds like what I need to do is insert a "hook" into the paramater values of a dynamically populated hidden field, and nest it in my functions.php. However I don't have the foggiest of how to create that hook. Essentially it would need to add all of the values together for a series of fields so that the resulting value is the selected value of those fields, as all of them default to blank with the exception of the one that has had a value inputted. For example, my "City" fields (there are about 70 of them) which dynamically appear when the proper province/state is selected. All have default "blank" values, so a hook that adds up all of their values and offers the result in the hidden field would only show the one value selected from the one city field dynamically available, allowing me to map that hidden field to the user "city" meta field. Can anyone possibly point me in the right direction?

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  10. I logged in to your site and I see now what you're trying to do. You can't use the merge tags like that because those selections have not yet been made. You can't set a default value for a field when the form is rendered, if the selection you want stored there has not yet been made.

    I would use the gform_pre_submission_filter to read the values which were submitted, then concatenate them, just like you're doing in your hidden field, and store that value.

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

    The line which concatenates all the values into one line is going to look something like this:

    [php]
    $combined = "Country: "        . $_POST['input_7']
              . "State: "          . $_POST['input_9']
              . "Province: "       . $_POST['input_8']
              . "City: "           . $_POST['input_21']
              . $_POST['input_22'] . $_POST['input_23']
              . $_POST['input_24'] . $_POST['input_25']
              . $_POST['input_26'] . $_POST['input_27']
              // etc, through field input_82
    $_POST['input_88'] = $combined;

    Basically, line 01 will just string together all the values submitted for Country, State, Province and City. Most of the cities will be empty, since they were not selected, so you are just concatenating empty strings. Eventually, the one selection will be added to the string.

    Then, on line 09, you assign this new combined string to the ID of the hidden field (it was field 88 in your form copy.)

    Let me know if that works for you.

    Posted 11 years ago on Tuesday January 1, 2013 | Permalink
  11. That worked beautifully. Thanks Chris. I created two and added them to my functions.php:

    <?php
    
    add_filter("gform_pre_submission_filter", "combine_provstate");
    function combine_provstate($form){
    
      //concatenate province fields
    $combined = $_POST['input_8']
              . $_POST['input_9'];
    $_POST['input_88'] = $combined;
    
    	  return $form;
    
    }
    ?>

    and

    <?php
    
    add_filter("gform_pre_submission_filter", "combine_city");
    function combine_city($form){
    
      //concatenate city fields
    $combined = $_POST['input_21']
              . $_POST['input_22']
    	  . $_POST['input_23']
    	  . $_POST['input_24']
    	  . $_POST['input_25']
    	  . $_POST['input_28']
    	  . $_POST['input_29']
    	  . $_POST['input_30']
    	  . $_POST['input_31']
    	  . $_POST['input_32']
    	  . $_POST['input_33']
    	  . $_POST['input_34']
    	  . $_POST['input_35']
    	  . $_POST['input_36']
    	  . $_POST['input_37']
    	  . $_POST['input_38']
    	  . $_POST['input_39']
    	  . $_POST['input_40']
    	  . $_POST['input_41']
    	  . $_POST['input_42']
    	  . $_POST['input_43']
    	  . $_POST['input_44']
    	  . $_POST['input_45']
    	  . $_POST['input_46']
    	  . $_POST['input_47']
    	  . $_POST['input_48']
    	  . $_POST['input_49']
    	  . $_POST['input_50']
    	  . $_POST['input_51']
    	  . $_POST['input_52']
    	  . $_POST['input_53']
    	  . $_POST['input_54']
    	  . $_POST['input_55']
    	  . $_POST['input_56']
    	  . $_POST['input_57']
    	  . $_POST['input_58']
    	  . $_POST['input_59']
    	  . $_POST['input_60']
    	  . $_POST['input_61']
    	  . $_POST['input_62']
    	  . $_POST['input_63']
    	  . $_POST['input_64']
    	  . $_POST['input_65']
    	  . $_POST['input_66']
    	  . $_POST['input_67']
    	  . $_POST['input_68']
    	  . $_POST['input_69']
    	  . $_POST['input_70']
    	  . $_POST['input_71']
    	  . $_POST['input_72']
    	  . $_POST['input_73']
    	  . $_POST['input_74']
    	  . $_POST['input_75']
    	  . $_POST['input_76']
    	  . $_POST['input_77']
    	  . $_POST['input_78']
    	  . $_POST['input_79']
    	  . $_POST['input_80']
    	  . $_POST['input_81']
    	  . $_POST['input_82'];
    
    $_POST['input_89'] = $combined;
    
    	  return $form;
    
    }
    ?>

    Now I can map these to my user meta. Thanks a ton.

    Posted 11 years ago on Wednesday January 2, 2013 | Permalink
  12. You're welcome.

    Posted 11 years ago on Wednesday January 2, 2013 | Permalink

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