# Calculated Fields Form Integration

Integrate Address Validation into Your WordPress Calculated Fields Form Pages.

## Demo

### Address Finder

![Activate Address Finder on your address collection forms-screenshot](/img/cff-af-demo.gif)

## Installation

This integration works by adding our Address Validation tools using CFF's form editor. Below are the instructions to add Postcode Lookup or Address Finder.

### Create Address Inputs

Add address input fields to your form. Use the form editor's `Single Line Text`. A basic address form to capture a correct UK address should have the following fields:

* Address line one (required)
* Address line two
* Address line three
* Post town (required)
* Postcode (required)

![Create address fields-screenshot](/img/cff-fields.png)

You can optionally include additional fields, which are documented in the [PAF documentation page](/docs/data/paf.md).

### Add Address Finder

#### Install and Initialise Plugin

Add the form's `shortcode` to the page.

Create an `html block` and add the two script tags at the bottom of your form to load the plugin and then to initialise it.

address-finder-init.htmlhtml

```html
<script src="https://cdn.jsdelivr.net/npm/@ideal-postcodes/address-finder-bundled"></script>

<script>
	document.addEventListener("DOMContentLoaded", function () {
		IdealPostcodes.AddressFinder.watch({
			apiKey: "ak_test",
			outputFields: {
				line_1: 'input[name="fieldname3_1"]',
				line_2: 'input[name="fieldname7_1"]',
				line_3: 'input[name="fieldname6_1"]',
				post_town: 'input[name="fieldname5_1"]',
				postcode: 'input[name="fieldname4_1"]',
			},
		});
	});
</script>
```

![Add the Address Finder Plugin-screenshot](/img/cff-setup.png)

You can optionally override CSS styles in the form editor, for example:

style-overrides.htmlhtml

```html
<style>
	@media only screen and (min-width: 641px) {
		ul.idpc_ul {
			min-width: 0 !important;
			width: calc(50% - 8px);
		}
	}
</style>
```

caution

Take special care to:

1. Insert your API Key in the `apiKey` field
2. Match the names of your target fields. If your Address Line One has the fieldname tag `fieldname3`, ensure that `line_1` reads `fieldname3_1`

If you wish to add an additional field, include the parameter name [from our documentation](/docs/data/paf.md). For instance, adding a `uprn` field with name `uprn` will look like:

widget-init.jsjavascript

```javascript
outputFields: {
  line_1: 'input[name="fieldname1_1"]',
  line_2: 'input[name="fieldname2_1"]',
  line_3: 'input[name="fieldname3_1"]',
  post_town: 'input[name="fieldname4_1"]',
  postcode: 'input[name="fieldname5_1"]',
  uprn: 'input[name="fieldname6_1"]'
}
```

## Configuration

See our [Address Finder Plugin Documentation](/docs/address-finder.md) if you wish to customise Address Finder.

See our [Postcode Lookup Plugin Documentation](/docs/postcode-lookup.md) if you wish to customise Postcode Lookup.

info

Still need help? Contact our support team via live chat on our website or email <support@ideal-postcodes.co.uk>.
