# Globotrip Backend Form Contracts

These contracts define the expected fields for the future PHP backend. The current MVP is still static and prevents real submission.

## Traveler Registration

Page: `sign-up.php`  
Contract: `traveler_registration`  
Future endpoint: `/backend/register-traveler.php`  
Future success redirect: `/traveler/`

Fields:

| Field | Type | Required | Notes |
|---|---:|---:|---|
| `form_key` | hidden | yes | `traveler_registration` |
| `default_dashboard` | hidden | yes | `traveler` |
| `source_page` | hidden | yes | `sign-up.php` |
| `full_name` | text | yes | Split into first/last name later if needed |
| `email` | email | yes | Unique account email |
| `password` | password | yes | Minimum 8 characters |
| `first_intent` | select | yes | Traveler's first intent |

Backend behavior later:

1. Create `users` row.
2. Set `default_dashboard='traveler'`.
3. Create `traveler_profiles` row.
4. Start session.
5. Redirect to `/traveler/`.

## Login

Page: `login.php`  
Contract: `login`  
Future endpoint: `/backend/login.php`

Fields:

| Field | Type | Required | Notes |
|---|---:|---:|---|
| `form_key` | hidden | yes | `login` |
| `email` | email | yes | Account email |
| `password` | password | yes | Current password |
| `dashboard_preview` | radio | no | Static preview only |

Backend behavior later:

1. Verify email/password.
2. Check `users.status`.
3. If admin, redirect `/admin/`.
4. If guide pending, redirect `/guide/application-status.php`.
5. Otherwise use `users.default_dashboard`.

## Guide Application

Page: `become-a-guide.php`  
Contract: `guide_application`  
Future endpoint: `/backend/apply-guide.php`  
Future success redirect: `/guide/application-status.php`

Fields:

| Field | Type | Required | Notes |
|---|---:|---:|---|
| `form_key` | hidden | yes | `guide_application` |
| `default_dashboard` | hidden | yes | `guide` |
| `application_status` | hidden | yes | `pending` |
| `full_name` | text | yes | Applicant name |
| `email` | email | yes | Can create or match user |
| `phone` | tel | yes | WhatsApp/contact |
| `location` | text | yes | City/country |
| `languages` | text | yes | Later convert to JSON |
| `experience_years` | select | yes | Simple range |
| `specialties` | text | yes | Later tags/JSON |
| `bio` | textarea | yes | Minimum 80 characters |

Backend behavior later:

1. Create or match `users` row.
2. Save `guide_applications` row.
3. Create or update `guides` with `application_status='pending'`.
4. Redirect to `/guide/application-status.php`.
5. Admin approval unlocks `/guide/` dashboard.

## Trip Request / Request Guide

Page: `request-guide.php`  
Contract: `trip_request`  
Future endpoint: `/backend/request-guide.php`  
Future success redirect: `/request-confirmation.php`

Fields:

| Field | Type | Required | Notes |
|---|---:|---:|---|
| `form_key` | hidden | yes | `trip_request` |
| `ai_itinerary_draft_id` | hidden | yes | Mock ID now |
| `destination_slug` | hidden | yes | `marrakech` in static demo |
| `request_status` | hidden | yes | `new` |
| `request_intent` | hidden | yes | Alpine value from intent cards |
| `traveler_name` | text | yes | Guest-friendly for MVP |
| `traveler_email` | email | yes | Main reply email |
| `traveler_phone` | tel | no | WhatsApp/phone |
| `preferred_contact` | select | yes | WhatsApp/email/both |
| `requested_dates` | text | yes | Later normalize to dates |
| `travelers_count` | select | yes | Later integer |
| `budget_range` | select | yes | Later normalize to min/max |
| `preferred_guide_id` | select | no | `auto_match` or guide ID |
| `message` | textarea | yes | Minimum 20 characters |
| `request_scope[]` | checkbox array | yes | Requested guide actions |

Backend behavior later:

1. Save or create user/traveler if guest flow is allowed.
2. Save `trip_requests` row.
3. Link to `ai_itinerary_drafts` when available.
4. Notify matching guides or selected guide.
5. Redirect to confirmation page.

## Admin Settings

Page: `admin/settings.php`  
Contract: `admin_settings`  
Future endpoint: `/backend/admin/settings.php`

Fields:

| Field | Type | Required | Notes |
|---|---:|---:|---|
| `form_key` | hidden | yes | `admin_settings` |
| `default_public_role` | select | yes | Keep traveler |
| `guide_redirect` | select | yes | Approved guide redirect |
| `pending_guide_redirect` | select | yes | Pending guide redirect |
| `admin_redirect` | select | yes | Admin redirect |

Backend behavior later:

1. Require admin session.
2. Save settings to a future `platform_settings` table or config file.
3. Add admin log row.
