Gravity Forms is a great WordPress Add-on for creating flexible and powerful forms with an easy-to-use WYSIWYG editor. Not only can you easily generate and customise basic fields such as textareas, dropdown lists and checkboxes, but Gravity Forms comes with built-in predefined options that it calls ‘Advanced Fields’.

Below is an example use of gravity forms on the wordpress platform being used as a cms


Using advanced fields in gravity forms

Advanced Fields allow you to quickly and easily add elements to your form such as a File Upload field, a CAPTCHA field or a multi-level Address field. These fields are great; however, by default fields such as the Address field are specific to the United States address format. The Gravity Form developers are aware of this, and instead of trying to build in different formats for each country and region, they developed hooks which can be used to create filters for each country.

Australian address format code customisation for gravity forms in wordpress

To add Australia’s address format to your Gravity Forms installation place the below code in your theme’s functions.php file.

// Gravity Forms Custom Address Hook (Australia)
add_filter(“gform_address_types”, “australian_address”, 10, 2);

    function australian_address($address_types, $form_id){
$address_types[“australia”] = array(
      “label” => “Australia”,
      “country” => “Australia”,
      “zip_label” => “Post Code”,
      “state_label” => “State”,
      “states” => array(“”, “Australian Capital Territory”, “New South Wales”, “Northern Territory”, “Queensland”,”South Australia”, “Tasmania”, “Victoria”, “Western Australia”)
);
return $address_types;
}

Once you’ve done this, in the Gravity Forms Address Field element you can now choose the ‘Australia’ Address Type.

Leave a Reply

Your email address will not be published. Required fields are marked *