/**
  * Gets and displays the rules for an address field, depending on the address type
  *
  * @access public
  * @static
  */
 public static function get_address_rule_values_select()
 {
     $address_type = rgpost('address_type');
     $value = rgpost('value');
     $id = rgpost('id');
     $address_field = new GF_Field_Address();
     $markup = '';
     switch ($address_type) {
         case '':
         case 'international':
             $items = $address_field->get_countries();
             break;
         case 'us':
             $items = $address_field->get_us_states();
             break;
         case 'canadian':
             $items = $address_field->get_canadian_provinces();
             break;
     }
     foreach ($items as $item) {
         $markup .= sprintf('<option value="%1$s" %2$s>%1$s</option>', $item, selected($value, $item, false));
     }
     $markup = sprintf('<select id="%1$s" name="%1$s" class="gfield_rule_select gfield_rule_value_dropdown">%2$s</select>', $id, $markup);
     echo $markup;
     die;
 }
/**
* prso_theme_gform_get_state_field
* 
* Called by 'prso_theme_gform_get_address_field' function in this document
* Essentially a copy and past of core code from Gravity Forms.
*
* Main reason this was copied out of gforms was the fact the original method is private
*
* NOTES: This functions uses almost the same code as Gravity Forms to create
* the field content. This approach was required as Gravity Forms does not yet
* have sufficient filters to allow changes to how fields and their labels are
* rendered. To ensure that the fields meet Zurb Foundation layout we needed to
* tweak the specific order of elements in the DOM.
*
* Although this avoids having to edit the Gravity Forms code base directly
* this still may break in the future if gforms change how their fields are rendered. 
*
*
* @access 	public
* @author	Ben Moody
*/
function prso_theme_gform_get_state_field($field, $id, $field_id, $state_value, $disabled_text, $form_id, $state_label)
{
    $state_dropdown_class = $state_text_class = $state_style = $text_style = $state_field_id = "";
    if (empty($state_value)) {
        $state_value = rgget("defaultState", $field);
        //for backwards compatibility (canadian address type used to store the default state into the defaultProvince property)
        if (rgget("addressType", $field) == "canadian" && !rgempty("defaultProvince", $field)) {
            $state_value = $field["defaultProvince"];
        }
    }
    $address_type = rgempty("addressType", $field) ? "international" : $field["addressType"];
    if (version_compare(GFForms::$version, '1.9.0', '>')) {
        $gf_address = new GF_Field_Address();
        $address_types = $gf_address->get_address_types($form_id);
    } else {
        $address_types = GFCommon::get_address_types($form_id);
    }
    $has_state_drop_down = isset($address_types[$address_type]["states"]) && is_array($address_types[$address_type]["states"]);
    if (IS_ADMIN && RG_CURRENT_VIEW != "entry") {
        $state_dropdown_class = "class='state_dropdown'";
        $state_text_class = "class='state_text'";
        $state_style = !$has_state_drop_down ? "style='display:none;'" : "";
        $text_style = $has_state_drop_down ? "style='display:none;'" : "";
        $state_field_id = "";
    } else {
        //id only displayed on front end
        $state_field_id = "id='" . $field_id . "_4'";
    }
    $tabindex = GFCommon::get_tabindex();
    $states = empty($address_types[$address_type]["states"]) ? array() : $address_types[$address_type]["states"];
    if (version_compare(GFForms::$version, '1.9.0', '>')) {
        $gf_state = new GF_Field_Address();
        $state_types = $gf_state->get_state_dropdown($states, $state_value);
    } else {
        $state_types = GFCommon::get_state_dropdown($states, $state_value);
    }
    $state_dropdown = sprintf("<select name='input_%d.4' %s {$tabindex} %s {$state_dropdown_class} {$state_style}>%s</select>", $id, $state_field_id, $disabled_text, $state_types);
    $tabindex = GFCommon::get_tabindex();
    $state_text = sprintf("<input type='text' name='input_%d.4' %s value='%s' {$tabindex} %s {$state_text_class} {$text_style} placeholder='" . apply_filters("gform_address_state_{$form_id}", apply_filters("gform_address_state", $state_label, $form_id), $form_id) . "'/>", $id, $state_field_id, $state_value, $disabled_text);
    if (IS_ADMIN && RG_CURRENT_VIEW != "entry") {
        return $state_dropdown . $state_text;
    } else {
        if ($has_state_drop_down) {
            return $state_dropdown;
        } else {
            return $state_text;
        }
    }
}