| @@ -30,9 +30,11 @@ | ||
| 30 | 30 | // Check if Dynamic Form Field module is enabled (Pro feature) |
| 31 | 31 | $is_dynamic_form_enabled = apply_filters('yatra_dynamic_form_field_enabled', false); |
| 32 | 32 | |
| 33 | 33 | // Get form configuration - returns default config if module disabled, custom config if enabled |
| 34 | -$form_config = yatra_get_booking_form_config(); | |
| 34 | +// Scoped to the trip being booked, so a field or section limited to certain | |
| 35 | +// trips (Pro) is neither rendered nor required here. | |
| 36 | +$form_config = yatra_get_booking_form_config(!empty($trip_id) ? (int) $trip_id : null); | |
| 35 | 37 | |
| 36 | 38 | |
| 37 | 39 | // Country list — pulls from the canonical FormatHelper source so every |
| 38 | 40 | // dropdown (admin, public booking, Pro modules) shows the same full |
| @@ -144,10 +146,17 @@ | ||
| 144 | 146 | <?php |
| 145 | 147 | break; |
| 146 | 148 | |
| 147 | 149 | case 'country': |
| 150 | + // Flag base is handed to the field (same contract as the phone | |
| 151 | + // widget) so country-select.js can build flag URLs without | |
| 152 | + // knowing the plugin URL. The select still renders and submits | |
| 153 | + // normally — the widget is a progressive enhancement over it. | |
| 154 | + $country_flag_base = \defined('YATRA_PLUGIN_URL') ? YATRA_PLUGIN_URL . 'assets/img/flags/' : ''; | |
| 148 | 155 | ?> |
| 149 | - <select id="<?php echo $field_id; ?>" name="<?php echo $field_name; ?>" <?php echo $required_attr; ?>> | |
| 156 | + <select id="<?php echo $field_id; ?>" name="<?php echo $field_name; ?>" <?php echo $required_attr; ?> | |
| 157 | + data-yatra-country-select | |
| 158 | + data-flag-base="<?php echo esc_url($country_flag_base); ?>"> | |
| 150 | 159 | <option value=""><?php echo esc_html(yatra_translate_form_string($field['placeholder'] ?? '') ?: __('Select Country', 'yatra')); ?></option> |
| 151 | 160 | <?php foreach ($countries as $code => $name) : ?> |
| 152 | 161 | <option value="<?php echo esc_attr($code); ?>" <?php echo selected($prefill_value, (string) $code, false); ?>> |
| 153 | 162 | <?php echo esc_html($name); ?> |
| @@ -202,18 +211,81 @@ | ||
| 202 | 211 | <?php |
| 203 | 212 | break; |
| 204 | 213 | |
| 205 | 214 | default: // text, email, tel, number |
| 206 | - ?> | |
| 207 | - <input | |
| 208 | - type="<?php echo esc_attr($field['type']); ?>" | |
| 209 | - id="<?php echo $field_id; ?>" | |
| 210 | - name="<?php echo $field_name; ?>" | |
| 211 | - placeholder="<?php echo esc_attr(yatra_translate_form_string($field['placeholder'] ?? '')); ?>" | |
| 212 | - <?php echo $required_attr; ?> | |
| 213 | - value="<?php echo esc_attr($prefill_value); ?>" | |
| 214 | - > | |
| 215 | - <?php | |
| 215 | + // Phone (tel) fields get the international country-code widget | |
| 216 | + // UNLESS it has been explicitly disabled in the (Pro) form | |
| 217 | + // builder. A missing key means ON, so every existing form and | |
| 218 | + // customized field keeps the widget without needing a re-save. | |
| 219 | + $is_phone_widget = (($field['type'] ?? '') === 'tel') | |
| 220 | + && (!array_key_exists('show_country_code', $field) || !empty($field['show_country_code'])); | |
| 221 | + | |
| 222 | + if ($is_phone_widget) { | |
| 223 | + // Split the stored value for display: an international value | |
| 224 | + // ("+9779806015400") is parsed into country + national part; | |
| 225 | + // a legacy bare number is left in the number box under the | |
| 226 | + // default country (never rewritten on display). | |
| 227 | + $pv = (string) $prefill_value; | |
| 228 | + $detected = \Yatra\Helpers\FormatHelper::detectPhoneCountry($pv); | |
| 229 | + if ($detected !== null) { | |
| 230 | + $p_iso = $detected['iso']; | |
| 231 | + $p_dial = $detected['dial']; | |
| 232 | + $p_national = $detected['national']; | |
| 233 | + } else { | |
| 234 | + $p_iso = \Yatra\Helpers\FormatHelper::getDefaultPhoneCountry(); | |
| 235 | + $p_dial = \Yatra\Helpers\FormatHelper::getDialingCode($p_iso); | |
| 236 | + $p_national = $pv; | |
| 237 | + } | |
| 238 | + | |
| 239 | + // Companion hidden field holding the chosen ISO. Array-style | |
| 240 | + // names (travelers[0][phone]) become travelers[0][phone_country]; | |
| 241 | + // the server combines dial code + national number on submit. | |
| 242 | + if (preg_match('/^(.*)\[([^\]]+)\]$/', $field_name, $mm)) { | |
| 243 | + $companion_name = $mm[1] . '[' . $mm[2] . '_country]'; | |
| 244 | + } else { | |
| 245 | + $companion_name = $field_name . '_country'; | |
| 246 | + } | |
| 247 | + | |
| 248 | + $flag_base = \defined('YATRA_PLUGIN_URL') ? YATRA_PLUGIN_URL . 'assets/img/flags/' : ''; | |
| 249 | + ?> | |
| 250 | + <div class="yatra-phone-field" data-yatra-phone | |
| 251 | + data-default-iso="<?php echo esc_attr($p_iso); ?>" | |
| 252 | + data-flag-base="<?php echo esc_url($flag_base); ?>"> | |
| 253 | + <button type="button" class="yatra-phone-country" aria-haspopup="listbox" aria-expanded="false" | |
| 254 | + aria-label="<?php esc_attr_e('Select country dialing code', 'yatra'); ?>"> | |
| 255 | + <img class="yatra-phone-flag" src="<?php echo esc_url($flag_base . strtolower($p_iso) . '.svg'); ?>" | |
| 256 | + alt="" width="22" height="16" loading="lazy"> | |
| 257 | + <span class="yatra-phone-dial">+<?php echo esc_html($p_dial); ?></span> | |
| 258 | + <span class="yatra-phone-caret" aria-hidden="true"></span> | |
| 259 | + </button> | |
| 260 | + <input | |
| 261 | + type="tel" | |
| 262 | + class="yatra-phone-number" | |
| 263 | + id="<?php echo $field_id; ?>" | |
| 264 | + name="<?php echo $field_name; ?>" | |
| 265 | + value="<?php echo esc_attr($p_national); ?>" | |
| 266 | + placeholder="<?php echo esc_attr(yatra_translate_form_string($field['placeholder'] ?? '')); ?>" | |
| 267 | + inputmode="tel" | |
| 268 | + autocomplete="tel-national" | |
| 269 | + <?php echo $required_attr; ?> | |
| 270 | + > | |
| 271 | + <input type="hidden" class="yatra-phone-iso" | |
| 272 | + name="<?php echo esc_attr($companion_name); ?>" | |
| 273 | + value="<?php echo esc_attr($p_iso); ?>"> | |
| 274 | + </div> | |
| 275 | + <?php | |
| 276 | + } else { | |
| 277 | + ?> | |
| 278 | + <input | |
| 279 | + type="<?php echo esc_attr($field['type']); ?>" | |
| 280 | + id="<?php echo $field_id; ?>" | |
| 281 | + name="<?php echo $field_name; ?>" | |
| 282 | + placeholder="<?php echo esc_attr(yatra_translate_form_string($field['placeholder'] ?? '')); ?>" | |
| 283 | + <?php echo $required_attr; ?> | |
| 284 | + value="<?php echo esc_attr($prefill_value); ?>" | |
| 285 | + > | |
| 286 | + <?php | |
| 287 | + } | |
| 216 | 288 | break; |
| 217 | 289 | } |
| 218 | 290 | ?> |
| 219 | 291 | </div> |
| @@ -618,8 +690,11 @@ | ||
| 618 | 690 | 'deposit_required' => $deposit_required, |
| 619 | 691 | 'deposit_percentage' => $deposit_percentage, |
| 620 | 692 | 'partial_payment' => $partial_payment, |
| 621 | 693 | 'partial_payment_percentage' => $partial_payment_percentage, |
| 694 | + // Tour start (when a date is already chosen) → Pro hides deposit/partial for | |
| 695 | + // tour-anchored payments when the tour is inside the balance-due window. | |
| 696 | + 'travel_date' => isset($booking->travel_date) ? (string) $booking->travel_date : '', | |
| 622 | 697 | ]); |
| 623 | 698 | |
| 624 | 699 | $has_flexible_options = $flexible_payments_enabled && !empty($payment_method_options); |
| 625 | 700 | ?> |
| @@ -817,8 +892,9 @@ | ||
| 817 | 892 | <label for="account_password"> |
| 818 | 893 | <?php esc_html_e('Password', 'yatra'); ?> <span class="required">*</span> |
| 819 | 894 | </label> |
| 820 | 895 | <input type="password" id="account_password" name="account_password" minlength="8" |
| 896 | + autocomplete="new-password" | |
| 821 | 897 | placeholder="<?php esc_attr_e('Minimum 8 characters', 'yatra'); ?>"> |
| 822 | 898 | </div> |
| 823 | 899 | <div class="yatra-form-group yatra-field-half"> |
| 824 | 900 | <label for="account_password_confirm"> |
| @@ -824,8 +900,9 @@ | ||
| 824 | 900 | <label for="account_password_confirm"> |
| 825 | 901 | <?php esc_html_e('Confirm Password', 'yatra'); ?> <span class="required">*</span> |
| 826 | 902 | </label> |
| 827 | 903 | <input type="password" id="account_password_confirm" name="account_password_confirm" minlength="8" |
| 904 | + autocomplete="new-password" | |
| 828 | 905 | placeholder="<?php esc_attr_e('Re-enter password', 'yatra'); ?>"> |
| 829 | 906 | </div> |
| 830 | 907 | </div> |
| 831 | 908 | <p class="yatra-field-hint" style="font-size: 13px; color: #6b7280; margin-top: 8px;"> |
| @@ -838,9 +915,9 @@ | ||
| 838 | 915 | </p> |
| 839 | 916 | </div> |
| 840 | 917 | <?php endif; ?> |
| 841 | 918 | </div> |
| 842 | -<?php elseif (!is_user_logged_in()) : ?> | |
| 919 | +<?php elseif (is_user_logged_in()) : ?> | |
| 843 | 920 | <!-- User is logged in --> |
| 844 | 921 | <div class="yatra-booking-section yatra-logged-in-notice"> |
| 845 | 922 | <div style="display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: #ecfdf5; border: 1px solid #10b981; border-radius: 8px;"> |
| 846 | 923 | <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#059669" stroke-width="2"> |