30 days free. No credit card. Full access from the moment you connect your site.

Start free trial

Add Contact Form Field

Contact Form 7 tag syntax is fiddly: the asterisk that marks a field required, the difference between options and values, the quoting rules for an option containing a space.

contact-form-7/add-form-field composes the tag from named arguments and inserts it into the template, with a label wrapper when you supply a label.

At a glance

Abilitycontact-form-7/add-form-field
ToolsetContact Form 7 — toolset/contact-form-7
GroupContact Form 7 › Fields & Template
RequiresContact Form 7, active on the site
Capabilitymanage_options, plus edit_contact_forms
SafetyWrites data
RepeatableNot idempotent — each call changes the row set, so re-running is not a no-op
Ships inAcrossAI Abilities Manager 0.0.34 and later

What this does not do

The new field name becomes available as a mail tag the moment it exists — but nothing adds it to a mail template. A field that collects data no notification references is the most common way information gets quietly lost. Follow with contact-form-7/update-mail to put [your-new-field] in the body.

How it works

Check contact-form-7/list-field-types first. The available types depend on which Contact Form 7 modules and add-ons are active, and a type the site does not know renders as literal text on the front end.

The field is appended by default — before or after the submit button depending on how the template is written. Pass prepend: true to put it first instead.

Pass required: true rather than writing the asterisk yourself. The tag is composed for you, and options with spaces in their values are quoted correctly.

Input

NameTypeRequiredWhat it is
form_idintegerYesForm post ID, as returned by contact-form-7/list-forms.
typestringYesField type, e.g. text, email, tel, textarea, select. Omit any trailing asterisk and use required instead.
namestringYesField name, used as the mail tag. Letters, digits, hyphens and underscores.
labelstringNoVisible label. Omit to emit the tag with no label wrapper.
requiredbooleanNo — defaults to falseMarks the field required.
optionsarray of stringsNoTag options, e.g. class:wide, id:enquiry-phone or maxlength:40. Write each as key:value; a value containing spaces is quoted for you, and one with a space but no key is refused.
valuesarray of stringsNoQuoted values, e.g. the choices of a select or radio field.
prependbooleanNo — defaults to falseInsert at the start of the template rather than the end.

What comes back

NameTypeWhat it is
form_idintegerThe form that was written.
fieldobjectThe field as parsed back out of the template.
tagstringThe tag that was composed.
templatestringThe template after the insert.
successbooleanWhether the call completed.
messagestringA one-line summary of what happened, suitable for showing a human.
error_codestringPresent only on failure — a stable machine-readable reason, such as a missing field, a wrong field type or an unmet confirmation.

Example

Ask your assistant:

Add a required phone field to form 42, labelled “Phone number”.

It resolves to one call:

{
  "ability": "contact-form-7/add-form-field",
  "parameters": {
    "form_id": 42,
    "type": "tel",
    "name": "your-phone",
    "label": "Phone number",
    "required": true
  }
}

Worth knowing

  • Not idempotent — calling it twice gives the form two fields with the same name, which Contact Form 7 handles badly.
  • The field is not in any mail template until you put it there.
  • A type this site has not registered renders as literal text on the front end rather than failing loudly.

Related abilities


Get the plugins:
AcrossAI Abilities Manager · AcrossAI MCP Manager

Browse the rest: Every ability, by category


Keep reading