CF7 Google Address Autocomplete
Integrates Contact Form 7 on Wordpress with Google Address Autocomplete. It can be attached to any standard text field and can populate other fields with the address components (street, city, state, zip, country).
by Ben Wagner · github.com/wagnerbenh/cf7-google-address-autocomplete · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/wagnerbenh/cf7-google-address-autocomplete/archive/refs/heads/main.zipIntegrates Google Address Autocomplete with Contact Form 7. It can be attached to any standard text field and can populate other fields with the address components (street, city, state, zip, country).
Description
This plugin provides a seamless way to add Google Address Autocomplete functionality to your Contact Form 7 forms. It's designed to be flexible and easy to use, allowing you to attach the autocomplete feature to any standard text field using a simple class. Additionally, it can automatically parse the selected address and populate other fields in your form with individual address components like street, city, state, zip code, and country.
Installation
- Install the plugin:
- Download the plugin from the WordPress repository or upload the plugin files to the
/wp-content/plugins/directory. - Activate the plugin through the 'Plugins' menu in WordPress.
- Download the plugin from the WordPress repository or upload the plugin files to the
- Contact Form 7:
- This plugin requires Contact Form 7 to be installed and activated.
Configuration
- Google Maps API Key:
- Go to Settings → CF7 Address Autocomplete.
- Enter your Google Maps API key. You can also define it as a PHP constant in your
wp-config.phpfile for better security:define( 'CF7GAA_GOOGLE_MAPS_API_KEY', 'YOUR_API_KEY' );
- Autocomplete Settings:
- Country Restriction: Restrict the autocomplete to specific countries (up to 5).
- Address Type Filter: Filter the results by address type (e.g., street addresses, cities).
- Target Field:
- Specify the CSS selector for the input field where the autocomplete should be attached. The default is
input.cf7gaa-address.
- Specify the CSS selector for the input field where the autocomplete should be attached. The default is
- Component Fields:
- Configure the plugin to automatically populate other fields in your form with the address components. You can map each component (street, city, state, zip, country) to a specific field in your form.
Usage
- Add a text field to your Contact Form 7 form:
- In your Contact Form 7 form settings, add a standard text field.
- Add the class
cf7gaa-addressto the field (or the custom class you defined in the settings). - Example:
[text* your-address class:cf7gaa-address placeholder "Start typing your address..."]
- Add fields for the address components (optional):
- If you want to automatically populate other fields with the address components, add them to your form.
- Example:
[text your-street] [text your-city] [text your-state] [text your-zip] [text your-country]
- Map the component fields in the plugin settings:
- Go to Settings → CF7 Address Autocomplete.
- In the "Auto-fill Component Fields" section, enter the names of the fields you created in the previous step. For example, for the "Street" component, you would enter
your-street.
FAQ
Does this plugin use the new Google Place Autocomplete Element?
No, this plugin uses the standard google.maps.places.Autocomplete library, which is a well-established and reliable solution. The description has been updated to reflect this.