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.

Change Country Value within Address Input (IE use US instead of United States)

  1. I figured before I break up every address field into separate inputs I wanted to see if there was a filter I could use to change the name (United States) AND value (US) of the country dropdown within the address input, I see I can utilize http://www.gravityhelp.com/documentation/page/Gform_countries but that appears to change both the label and the value. Is there any hidden gem for array('US' => 'United States', 'CA' => 'Canada')

    Posted 12 years ago on Monday June 11, 2012 | Permalink
  2. Looks like this user post a solution that may potentially work for you:

    http://www.gravityhelp.com/forums/topic/use-2-letter-country-codes-in-value-attribute-of-dropdown#post-8984

    Posted 12 years ago on Wednesday June 13, 2012 | Permalink
  3. Thanks for the reply Rob. Hmm it looks like he was importing his own fields. In the current scenario we are utilizing the Advanced Address field. We can always break up the individual address fields into separate inputs but wanted to see if the method I mentioned in my previous post allows for associative arrays for the data.

    Posted 12 years ago on Wednesday June 13, 2012 | Permalink
  4. Hello Aaron,
    Unfortunately, we don't a "hidden gem" that allows you to specify different values for the country field choices. One alternative is use jQuery to replace the values on the client side.

    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  5. Alex, do you have an example of how to replace the value? I am looking to do this for a drop down populated with a taxonomy.

    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  6. Here is a code snippet to update the value of a couple of countries in an address field.

    <script type="text/javascript">
    //NOTE: replace input_157_4_6 with your actual input ID (inspect the markup/page source to find out what your ID is)
    jQuery("#input_157_4_6").children("option").each(function(){
        var newVal = jQuery(this).val();
        switch(jQuery(this).val()){
            case "Brazil" :
                newVal = "BR";
            break;
    
            case "United States" :
                newVal = "US";
            break;
        }
        jQuery(this).val(newVal);
    });
    
    </script>
    Posted 12 years ago on Thursday June 14, 2012 | Permalink
  7. Thanks Alex. I am working through this but please excuse my lack of experience with these couple of questions:

    case "Brazil" would brazil be the Label of Value we are looking to replace
    (i am assuming it is the value)

    would this code need to be put into pre_submission or something along those lines in order for it to run? I have it being added as script to that specific page not as a part of functions.php but the values still show up as the default values from the drop down (populated with a taxonomy)

    Posted 12 years ago on Friday June 15, 2012 | Permalink
  8. Making Progress--for anyone else trying to do something similar I have the drop down value now being grabbed then changed and displayed in a field:

    add_filter("gform_pre_render_4", "monitor_dropdown");
    function monitor_dropdown($form){
    
    ?>
        <script type="text/javascript">
        jQuery(document).ready(function(){
    
            jQuery('#input_4_40').bind('change', function()
            {
                //get selected value from drop down;
                var selectedValue = jQuery("#input_4_40").val();
    
    jQuery("#input_4_40").children("option").each(function(){
        var newVal = jQuery(this).val();
        switch(jQuery(this).val()){
            case "236" : newVal = "8";
            break;
    
            case "237" : newVal = "8";
            break;
    
            break;
        }
        jQuery(this).val(newVal);
    
    });
    
                //populate a text field with the selected drop down value
                jQuery("#input_4_61").val(selectedValue);
    
            });
        });
        </script>
    <?php
    
    return $form;
    }
    Posted 12 years ago on Friday June 15, 2012 | Permalink