> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.metalocator.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Aligning Lead Form Inputs with Search Selections

---

In some implementations, it is desirable for a lead form field to automatically reflect the user’s active search choices from the locator search form. Common examples include:

* A visitor searches for **53211**, and that value should be passed into the lead form as a hidden field.
* A visitor searches for a **Product**, finds a dealer, and the product list in the lead form should automatically align with the product chosen in the search form.

The search form state is exposed to the Lead Form template as:

```
ml_formstate
```

## Using Initialize with Search (Category Fields Only)

When using a **Category** field in the Lead Form, the built-in **Initialize with Search** checkbox allows the selected category from the search form to automatically populate the lead field. This requires no template editing.

Steps to enable this behavior:

1. Navigate to **Leads > Lead Form** in the main interface.
2. Click **Add Field**.
3. Choose **Category** from the list of available field types.
4. Drag the Category field to the desired position on the form.
5. Click the Category field to open its settings.
6. Set **Target Custom Field** to an unused custom field (for example, _Custom 5_).
7. Check **Initialize with Search**.
8. Apply the style **Hide** to the field if it should not be visible on the form.
9. Save the interface and test.

With these settings applied, the selected category from the search form will automatically populate the designated custom field when the lead is submitted.

## Using Template Logic (Custom Lead Fields)

For all other field types the **template method** must be used. This method relies on accessing `ml_formstate` inside the Lead Form template to read values from the active search.

Example: Hidden Input Populated from Search State

The following example uses the selected categories (`tags` in code) from the search form to populate a hidden custom field named `custom2`:

```
<input type="hidden" name="custom2" value="{{#tocsv ml_formstate.tags}}" />
```

Example: Pre-Select a Dropdown Option

A `<select>` option can be set to selected if the corresponding category is active in the search:

```
<option value="Cleaning" {{#if_in_array 312 ml_formstate.tags }}selected{{/if_in_array}}>Cleaning</option>
```

In this example:

* `312` is the internal category ID.
* If that category is present in the active search form selections, the option will render with the `selected` attribute.