@extends('layouts.app') @section('title', 'API Documentation') @section('content')
Submit form data from external websites to FormHub. Each project requires a valid API key sent in the request header.
{{ url('/api/form-submit') }}
| Header | Value | Description |
|---|---|---|
X-API-Key | fk_xxxxxxxx... | Your project API key (required) |
Content-Type | application/json | For JSON requests |
Accept | application/json | Recommended |
{
"form_name": "Contact",
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890",
"message": "Hello, I would like more information.",
"company": "Acme Inc"
}
| Field | Type | Required | Description |
|---|---|---|---|
form_name | string | No | Form identifier (default: "Contact", or "Chatbot" when source is chatbot) |
form_type | string | No | Alias for form_name |
source | string | No | website (default) or chatbot |
external_id | string | No | Unique chatbot conversation ID (deduplicates resubmits). Alias: conversation_id |
name | string | No | Visitor name (stored as visitor_name) |
email | string | No | Visitor email |
phone | string | No | Visitor phone |
submitted_url | string | No | Page URL where the form was submitted |
utm_source | string | No | Marketing source (e.g. google, facebook). Also parsed from submitted_url if present |
utm_medium | string | No | Marketing medium (e.g. cpc, email) |
utm_campaign | string | No | Campaign name |
| custom fields | mixed | No | Any additional fields are stored in form_data |
Alternative: pass api_key in the request body instead of the header. Hidden honeypot fields (honeypot, website_url_hp) must remain empty.
curl -X POST "{{ url('/api/form-submit') }}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-API-Key: fk_your_api_key_here" \
-d '{
"form_name": "Contact",
"name": "John Doe",
"email": "john@example.com",
"phone": "+1234567890",
"message": "Hello!"
}'
<form action="{{ url('/api/form-submit') }}" method="POST">
<input type="hidden" name="api_key" value="fk_your_api_key_here">
<input type="text" name="form_name" value="Contact">
<input type="text" name="name" placeholder="Name" required>
<input type="email" name="email" placeholder="Email" required>
<input type="tel" name="phone" placeholder="Phone">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit">Send</button>
</form>
{
"success": true,
"message": "Form submitted successfully.",
"data": {
"id": 42,
"form_name": "Contact",
"status": "new",
"is_duplicate": false,
"submitted_at": "2026-07-30T12:00:00+00:00"
}
}
| Code | Example |
|---|---|
| 401 | |
| 422 | |
| 429 | |
| 500 | |
Connect enquiry forms from custom CMS or Laravel websites to FormHub. Leads appear in Submissions with source Website.
Send leads from your CMS server (PHP/Laravel controller), not from browser JavaScript. This keeps the API key in .env and avoids exposing it in HTML.
1. Environment — add to the CMS site .env:
FORMHUB_URL={{ url('/') }}
FORMHUB_API_KEY=fk_your_api_key_here
2. Config — config/formhub.php:
<?php
return [
'url' => rtrim(env('FORMHUB_URL', '{{ url('/') }}'), '/'),
'api_key' => env('FORMHUB_API_KEY'),
];
3. Service — app/Services/FormHubService.php:
<?php
namespace App\Services;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
class FormHubService
{
public function submit(array $payload): array
{
$response = Http::timeout(15)
->acceptJson()
->withHeaders(['X-API-Key' => config('formhub.api_key')])
->post(config('formhub.url') . '/api/form-submit', $payload);
if ($response->failed()) {
throw new RequestException($response);
}
return $response->json();
}
}
4. Controller — validate the CMS form, then forward to FormHub:
public function store(Request $request, FormHubService $formHub)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|max:255',
'phone' => 'nullable|string|max:50',
'message' => 'nullable|string|max:5000',
'honeypot' => 'nullable|max:0',
]);
if ($request->filled('honeypot')) {
abort(422, 'Spam detected.');
}
$formHub->submit([
'form_name' => 'Contact',
'name' => $validated['name'],
'email' => $validated['email'],
'phone' => $validated['phone'] ?? null,
'message' => $validated['message'] ?? null,
'submitted_url' => url()->previous(),
// any extra CMS fields are stored in form_data:
'city' => $request->input('city'),
]);
return back()->with('success', 'Thank you! We will contact you soon.');
}
5. CMS form — post to your Laravel route (not FormHub directly):
<form method="POST" action="@{{ route('contact.store') }}">
@@csrf
<input type="text" name="honeypot" value="" style="display:none" tabindex="-1" autocomplete="off">
<input type="text" name="name" required>
<input type="email" name="email" required>
<input type="tel" name="phone">
<textarea name="message"></textarea>
<button type="submit">Send</button>
</form>
Use the same API key and change form_name per form (e.g. Contact, Brochure, Site Visit). FormHub filters submissions by form name.
| CMS field | FormHub field | Notes |
|---|---|---|
| Name | name | Also accepts full_name, fname + lname |
email | Used for duplicate / repeated lead detection | |
| Phone | phone | Also accepts mobile |
| Form type | form_name | e.g. Contact, Enquiry |
| Page URL | submitted_url | Optional but recommended |
| Custom fields | any key | Stored in form_data (city, budget, etc.) |
Send chatbot leads to FormHub using the same POST /api/form-submit endpoint. Set source to chatbot so leads appear separately from website forms.
{
"source": "chatbot",
"form_name": "Chatbot",
"external_id": "chat_abc123",
"name": "John Doe",
"email": "john@example.com",
"phone": "9999999999",
"message": "Interested in 3BHK. Wants a site visit.",
"submitted_url": "https://yoursite.com/",
"intent": "site_visit",
"chat_transcript": "User: Hi... Bot: Please share your email..."
}
$formHub->submit([
'source' => 'chatbot',
'form_name' => 'Chatbot',
'external_id' => $conversationId,
'name' => $lead['name'],
'email' => $lead['email'] ?? null,
'phone' => $lead['phone'] ?? null,
'message' => $lead['summary'] ?? null,
'submitted_url' => $lead['page_url'] ?? null,
'chat_transcript' => $lead['transcript'] ?? null,
]);
external_id (or conversation_id) prevents duplicate leads from the same chat session.