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.

Add Custom Field to Address Field Set

  1. willmccreery
    Member

    I apologize if this has been discussed elsewhere.

    Does anyone know how to hook a custom field into the address advanced field?

    For instance: I would like my address fields to display : address/city/county/state/zip in that order, so simply renaming labels doesn't do me any good.

    Posted 13 years ago on Monday July 11, 2011 | Permalink
  2. Have you tried the filter to create a new address type?

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

    Posted 13 years ago on Monday July 11, 2011 | Permalink
  3. I've want to place an new address type for germany. Mr. Flahaut shows the link for doing that above. On that page the example locate in common.php.
    Could I change that code without side effects with the auto updates?

    The other source parts, inclusive add_filter(), are also edit/place in the common.php?

    Which files could I change also, without side effects with auto update?
    Where could I find some of these global information?

    Posted 12 years ago on Tuesday August 14, 2012 | Permalink
  4. David Peralty

    This code goes in your theme's functions.php file and as such wouldn't be touched by a Gravity Forms update. You don't edit Gravity Forms core code to utilize our hooks system.

    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 12 years ago on Tuesday August 14, 2012 | Permalink
  5. Thank you David, I appappreciate your tip with the php-file.

    That part is nearly done.

    /**
     * Changes for Gravity-Forms
     * (c) 2012 Hartmut Schöpke, Xiega UG, Dortmund,
     *
     * german adress format
     */
    
    add_filter("gform_address_types", "german_address", 10, 2);
    function german_address($address_types, $form_id){
        $address_types["german"] = array(
                                        "label" => "deutsch",
                                        "country" => "Deutschland",
                                        "zip_label" => "PLZ",
                                        "state_label" => "Bundesland",
                                        "states" => array("", "Baden-Württemberg", "Bayern", "Berlin", "Brandenburg", "Bremen", "Hamburg", "Hessen", "Mecklenburg-Vorpommern", "Niedersachsen", "Nordrhein-Westfalen", "Rheinland-Pfalz", "Saarland", "Sachsen", "Sachsen-Anhalt", "Schleswig-Holstein", "Thüringen")
        );
        return $address_types;
    }
    add_filter("gform_address_street", "change_address_street", 10, 2);
    function change_address_street($label, $form_id){
        return "Straße";
    }
    add_filter("gform_address_display_format", "address_format");
    function address_format($format){
        return "zip_before_city";
    }

    ---

    I've got difficulties with the css-part.

    First I've included the css below all other in the WP-Thems css file; but It shows no effect.
    Then I traced it in firebug and oh, what a miracle. the css file /plugins/gravityforms/css/forms.css is the last in order of the cascade.
    Then I put the new css-parts there and It works.

    /**
     * Chnages for gravity forms
     * (c) 2012 Hartmut Schöpke, Xiega UG, Dortmund
     *
     * formular design for zip and city as customary in germany
     */
    .gform_wrapper .ginput_complex #input_1_3_5_container {
    	width: 30%;
    }
    .gform_wrapper .gfield_error .ginput_complex #input_1_3_5_container {
    	width: 30%;
    }
    .gform_wrapper .ginput_complex #input_1_3_3_container {
    	width: 69%;
    }
    .gform_wrapper .gfield_error .ginput_complex #input_1_3_3_container {
    	width: 69%;
    }

    But now I think I've got an Problem again with auto updates.

    Possible the Problem is because I use the WP4FB plugin? The three gravity styles (I've got in preview) aren't in the wp4fb-page (page for a facebook-app). To get nearly the same result I must include all of the forms.css-code on top of the wp4fb.css.
    Unfortunately the css-parts for my address fields have no effect in that file (neither, between form and wp4fb parts, nor at the end) because the forms.css in /plugins/gravityforms override the style.

    Is there any possibility to solve the problem with auto-update (or doesn't the update overwrite that file?).

    Until I've solved the problem you could find an Example of the generated form here.

    Posted 12 years ago on Wednesday August 15, 2012 | Permalink
  6. Do not modify the plugin forms.css file. Those changes, as you know, will be lost on upgrade. If the custom CSS you added does not appear to have any effect, you need to make the selectors more specific, or you need to add the !important property. Try this:

    [css]
    .gform_wrapper .ginput_complex #input_1_3_5_container {
    	width: 30%!important;
    }
    .gform_wrapper .gfield_error .ginput_complex #input_1_3_5_container {
    	width: 30%!important;
    }
    .gform_wrapper .ginput_complex #input_1_3_3_container {
    	width: 69%!important;
    }
    .gform_wrapper .gfield_error .ginput_complex #input_1_3_3_container {
    	width: 69%!important;
    }

    The important property should force this rule to apply above all other rules.

    More reading on CSS Specificity:
    http://css-tricks.com/specifics-on-css-specificity/

    Posted 12 years ago on Wednesday August 15, 2012 | Permalink