Booking Form Rentals - Issue Resolution

📄 General
← Back to Documentation
# Booking Form Rentals - Issue Resolution ## Problem Booking via web form type "rentals" is not being created, and no errors are returned to the user. ## Root Causes Identified ### 1. **Nested Form Tags** ✅ FIXED - **Issue**: There were two `<form>` tags - one in `venue.blade.php` and another in `booking-form-rentals.blade.php` - **Impact**: Nested forms are invalid HTML and prevent proper form submission - **Fix**: Removed the outer form tag from `venue.blade.php`, keeping only the form in the partial ### 2. **Silent Validation Failures** (Likely Issue) - **Issue**: Form validation may be failing but errors aren't being displayed - **Impact**: User doesn't know what's wrong, booking appears to "do nothing" - **Potential Causes**: - Missing required fields (check_in, check_out dates) - Invalid date formats - Missing venue_id or other hidden fields - Validation rules in BookingController not matching form fields ### 3. **Missing Required Data** - **Issue**: The form may not be sending all required data for booking creation - **Required Fields for Rentals**: - `venue_id` ✅ (hidden field exists) - `booking_type` ✅ (hidden field exists with value "rentals") - `check_in` ✅ (date input exists) - `check_out` ✅ (date input exists) - `rooms` (optional array - quantity steppers) - `services` (optional array - quantity steppers) - `packages` (optional array - quantity steppers) ## Solutions Implemented ### 1. Fixed Nested Forms **File**: `resources/views/web/venue.blade.php` **Change**: Removed outer form wrapper, now only includes the partial: ```php @if(($bookingType ?? 'rentals') === 'rentals') @include('web.partials.booking-form-rentals') ``` ### 2. Enhanced Error Display The form already has error display at the top: ```php @if ($errors->any()) <div class="bg-red-50 border-l-4 border-red-500 p-4 mb-6 rounded-lg"> ... </div> @endif ``` ## Debugging Steps ### Step 1: Check Browser Console 1. Open browser Developer Tools (F12) 2. Go to Console tab 3. Try submitting the form 4. Look for JavaScript errors ### Step 2: Check Network Tab 1. Open Developer Tools (F12) 2. Go to Network tab 3. Submit the form 4. Look for the POST request to `/web/bookings` 5. Check the response: - Status code (200, 302, 422, 500) - Response body (errors, validation messages) ### Step 3: Check Laravel Logs ```bash tail -f storage/logs/laravel.log ``` Look for: - Validation errors - Database errors - Exception stack traces ### Step 4: Test with Minimal Data Try submitting with just: - Check-in date (tomorrow) - Check-out date (day after tomorrow) - No rooms/services selected ## Common Issues & Solutions ### Issue 1: Dates Not Being Sent **Symptom**: Form submits but validation fails on dates **Solution**: Ensure date inputs have values before submission ```javascript // Add this before form submission const checkIn = document.querySelector('input[name="check_in"]').value; const checkOut = document.querySelector('input[name="check_out"]').value; if (!checkIn || !checkOut) { Swal.fire({ icon: 'warning', title: 'Missing Dates', text: 'Please select check-in and check-out dates' }); return false; } ``` ### Issue 2: Quantity Steppers Not Sending Data **Symptom**: Rooms/services selected but not in POST data **Solution**: Check that quantity inputs have proper names: ```html <input type="number" name="rooms[{{ $room->id }}]" value="0" min="0" max="10"> ``` ### Issue 3: CSRF Token Missing **Symptom**: 419 error or "Page Expired" **Solution**: Ensure @csrf is in the form (already present) ### Issue 4: Client ID Missing **Symptom**: Database error about missing client_id **Solution**: Check BookingController line 229: ```php 'client_id' => Auth::user()->client->id ?? 1, ``` User might not have a client record. ## Testing Checklist - [ ] Form submits without JavaScript errors - [ ] Network request shows POST to `/web/bookings` - [ ] Response status is 302 (redirect) or shows validation errors - [ ] Laravel logs show booking creation attempt - [ ] User is logged in (@auth check passes) - [ ] Check-in and check-out dates are filled - [ ] Dates are in correct format (YYYY-MM-DD) - [ ] At least one room/service is selected (or form allows zero) - [ ] User has a client record in database ## Recommended Immediate Actions ### 1. Add Form Submission Logging Add to the form: ```html <form id="rentals-form" action="{{ route('bookings.store') }}" method="POST" onsubmit="console.log('Form submitting...', new FormData(this))"> ``` ### 2. Add Validation Error Display Already present, but ensure it's visible. ### 3. Check BookingController Validation The controller expects: ```php 'check_in' => 'required|date|after_or_equal:today', 'check_out' => 'required|date|after:check_in', ``` Make sure dates meet these requirements. ### 4. Test with Browser DevTools 1. Fill form with valid data 2. Open Network tab 3. Submit form 4. Check request payload 5. Check response ## Expected Behavior After Fix 1. User fills in check-in and check-out dates 2. User optionally selects rooms/services 3. User clicks "Proceed to Booking" 4. Form submits to `/web/bookings` (POST) 5. BookingController validates data 6. Booking is created in database 7. User is redirected to confirmation page 8. Success message is displayed ## Files Modified 1. `resources/views/web/venue.blade.php` - Removed nested form tag 2. `BOOKING_FORM_RENTALS_FIX.md` - This documentation ## Next Steps 1. Test the form submission with browser DevTools open 2. Check Laravel logs for any errors 3. Verify user has client record in database 4. Ensure dates are being sent in correct format 5. Check if validation is passing 6. Verify booking is being created in database ## Additional Debugging Code Add this to `BookingController@store` at line 84 (after validation): ```php Log::info('Booking form data received:', [ 'all_input' => $request->all(), 'validated' => $validated, 'user_id' => Auth::id(), 'has_client' => Auth::user()->client !== null ]); ``` This will log all form data to help identify what's missing.