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:
Navigate to Leads > Lead Form in the main interface.
Click Add Field.
Choose Category from the list of available field types.
Drag the Category field to the desired position on the form.
Click the Category field to open its settings.
Set Target Custom Field to an unused custom field (for example, Custom 5).
Check Initialize with Search.
Apply the style Hide to the field if it should not be visible on the form.
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:
312is the internal category ID.If that category is present in the active search form selections, the option will render with the
selectedattribute.
