# Form Submission

Use this endpoint to submit a form from your own code, the same way a visitor submits it on the site.

### `POST` `/form-submit`

Submit a form and create an entry.

**Permission:** `fluentform_entries_viewer`

The check runs against `form_id`.

**Parameters**

Body

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `form_id` | integer | | Required. The form to submit. |
| `data` | string | | Required. The field values as one URL-encoded string, like a serialized HTML form: `names[first_name]=Jane&email=jane%40example.com`. Send a string, not a JSON object. |

The keys inside `data` are the field `name` attributes from the form's `form_fields` (see `GET /forms/{form_id}`). Keys that are not fields of the form are dropped. These extra keys are also accepted inside `data`:

| Key | Description |
|-----|-------------|
| `_wp_http_referer` | Path of the page the form was on, such as `/contact/`. Stored as the entry's `source_url`. |
| `__fluent_form_embded_post_id` | ID of the post or page the form was embedded in. |
| `g-recaptcha-response`, `h-captcha-response`, `cf-turnstile-response` | Captcha tokens. Required when the form uses that captcha. |
| `_fluentform_{form_id}_fluentformnonce` | Form nonce. Checked only when the `fluentform/nonce_verify` filter turns nonce checks on. |
| `item_{form_id}__fluent_sf` | Honeypot field. When the honeypot is on in global settings, send it with an empty value. |
| `__fluent_protection_token_{form_id}` | Spam protection token. Required when token-based spam protection is on in global settings. |

**Example request**

```bash
curl https://your-site.com/wp-json/fluentform/v1/form-submit \
  -u 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' \
  --data-urlencode 'form_id=12' \
  --data-urlencode 'data=names[first_name]=Jane&names[last_name]=Doe&email=jane@example.com&message=Hello there&_wp_http_referer=/contact/'
```

**Example response**

When the form's confirmation shows a message on the same page:

```json
{
  "insert_id": 1046,
  "result": {
    "message": "<p>Thank you for your message. We will get in touch with you shortly.</p>",
    "action": "hide_form"
  },
  "error": ""
}
```

When the confirmation redirects to a page or URL, `result` holds `redirectUrl` and `message` instead:

```json
{
  "insert_id": 1046,
  "result": {
    "redirectUrl": "https://your-site.com/thank-you/",
    "message": ""
  },
  "error": ""
}
```

- `insert_id` is the new entry ID.
- `result.message` is the confirmation message with smart codes replaced. `result.action` is `hide_form` or `reset_form`.
- `error` is an empty string. It holds an exception message only when an integration throws during processing and `WP_DEBUG` is on.
- An entry flagged as spam by Akismet or CleanTalk, with "skip processing" set, still returns `insert_id` and `result`, without `error`.
- Forms with payment fields follow the payment flow. Their response shape is set by the payment method and is not covered here.

**Errors**

Error bodies use an `errors` key, not `message`.

- `422` with `{"errors": "Sorry, No corresponding form found"}` when `form_id` does not match a form.
- `423` with field errors when validation fails. Each key is a field name. Each value maps the failed rule to its message:

  ```json
  {
    "errors": {
      "email": {
        "required": "This field is required"
      },
      "names[first_name]": {
        "required": "This field is required"
      }
    }
  }
  ```

- `422` with `{"errors": {"restricted": ["..."]}}` when a form restriction blocks the submission: entry limit, schedule, login required, empty submission, or IP, country or keyword rules.
- `422` with `{"errors": {"g-recaptcha-response": ["reCaptcha verification failed, please try again."]}}` when a captcha check fails. hCaptcha and Turnstile use their own field keys.
- `422` with `{"errors": {"_fluentformnonce": ["Nonce verification failed, please try again."]}}` when nonce checks are on and the nonce is wrong.
- `422` with `{"errors": "Sorry! You can not submit this form at this moment!"}` when the honeypot field is missing or filled.
- `422` with `{"errors": "Suspicious activity detected. Form submission blocked"}` when token-based spam protection rejects the request.
- `429` with `{"errors": {"restricted": ["Too Many Requests."]}}` when the same IP address sent 5 or more entries in the last 30 seconds. The `fluentform/max_submission_count` and `fluentform/min_submission_interval` filters change these limits.

**Side effects**

This endpoint runs the same pipeline as a front-end submission:

- Runs all validation: field rules, restrictions, captcha, honeypot, spam checks and the per-IP rate limit.
- Saves the entry, its entry details and a unique entry hash. The entry's `user_id` is the user making the request.
- Fires `fluentform/before_insert_submission`, `fluentform/submission_inserted` and `fluentform/before_submission_confirmation`. Email notifications, integrations and webhooks run from `fluentform/submission_inserted`.
