Booking Form
* Dynamic form customization requires the Dynamic Form Field module (Pro).
*
* @package Yatra
*
* Expected variables:
* - $trip_id
* - $trip_slug (optional)
* - $total_travelers
* - $deposit_required
* - $deposit_percentage
* - $partial_payment
* - $partial_payment_percentage
* - $enabled_gateways
*
* Form Configuration Structure:
* - contact_form: Lead traveler contact information (prefix: contact_)
* - emergency_contact_form: Emergency contact details (prefix: emergency_)
* - traveler_form: Individual traveler details (array format: travelers[1][field_id])
*/
if (!defined('ABSPATH')) {
exit;
}
// Check if Dynamic Form Field module is enabled (Pro feature)
$is_dynamic_form_enabled = apply_filters('yatra_dynamic_form_field_enabled', false);
// Get form configuration - returns default config if module disabled, custom config if enabled
$form_config = yatra_get_booking_form_config();
// Country list — pulls from the canonical FormatHelper source so every
// dropdown (admin, public booking, Pro modules) shows the same full
// ISO-3166-1 list. Operators that want a "popular countries" subset
// or custom ordering apply the `yatra_countries_list` filter.
$countries = \Yatra\Helpers\FormatHelper::getCountries();
/**
* Render a single form field based on configuration
*
* @param array $field Field configuration
* @param string $prefix Field name prefix (e.g., 'contact_', 'emergency_')
* @param array $countries Country list for country fields
* @param string $custom_name Optional custom field name (for array-style names like travelers[1][field_id])
* @param string $custom_id Optional custom field ID
*/
if (!function_exists('yatra_render_form_field')) {
function yatra_render_form_field($field, $prefix = '', $countries = [], $custom_name = null, $custom_id = null) {
if (empty($field['enabled'])) {
return;
}
// Display-only text block: render admin-authored content (safe HTML) at this
// position between fields. It is NOT an input — no label, name, value or
// required handling — so it submits nothing and is never validated.
if (($field['type'] ?? '') === 'text_block') {
$tb_width = 'yatra-field-full';
if (($field['width'] ?? '') === 'half') {
$tb_width = 'yatra-field-half';
} elseif (($field['width'] ?? '') === 'third') {
$tb_width = 'yatra-field-third';
}
?>
.
$is_dob = (stripos($field_id, 'birth') !== false || stripos($field_id, 'dob') !== false
|| stripos($field_name, 'birth') !== false || stripos($field_name, 'dob') !== false);
$dob_attr = $is_dob ? ' data-yatra-dob="1" max="' . esc_attr(date('Y-m-d')) . '"' : '';
// Native date inputs ignore the placeholder, but once booking.js
// upgrades the field to a flatpickr text input the placeholder is
// what keeps it visually consistent with the other text fields
// (otherwise it renders blank). Use the field's own placeholder
// when set, else a format hint matching flatpickr's Y-m-d output.
$date_placeholder = !empty($field['placeholder'])
? yatra_translate_form_string($field['placeholder'])
: 'YYYY-MM-DD';
?>
value=""
>