Reputation: 309
I am working in a form with two separated divs and When I click the Button in the bottom of the form it should redirect me to a new page but as of now it does nothing.
I already tried few things that might fix it like:
Here's my current progress (Picture of web page where the form is placed):
And here's my source code for the view (SelectFlight.blade.php):
@extends('layouts.app')
@section('title', 'Select Flight')
@section('content')
<form method="GET" action="{{route('PassengerRegister')}}" autocomplete = "off">
@csrf
<div class="container">
<div class="row justify-content-center">
<div class="col-md-13">
<div class="card">
<div class="card-header bg-primary">
<i class="fas fa-plane-departure"></i><b>
{{ __('Select your Departing Flight') }}
@foreach($flights_depart as $flight)
{{ "(".$flight->date_departure.")" }}
@break
@endforeach
</b></div>
<div class="card-body">
@csrf
<table class="table">
<thead>
<tr>
<p style = "text-align: center">
<b>
List of flights from
{{$depart_source_country}} to
@foreach($depart_destination_country as $destination)
{{$destination->country_name}}
@endforeach
</b>
</p>
<th scope="col">FLIGHT NO.</th>
<th scope="col">DEPARTURE TIME / ARRIVAL TIME</th>
<th scope="col">DEPARTURE LOCATION </th>
<th scope="col">ARRIVAL LOCATION </th>
<th scope="col">FLIGHT DURATION </th>
<th scope="col">FLIGHT TYPE </th>
<th scope="col">RESERVE TICKET </th>
</tr>
</thead>
<tbody>
@php
$counter1 = 0;
$duration_1 = '';
$flight_type_name = '';
$flight_type_price;
$total_fare;
@endphp
@foreach($flights_depart as $flight)
<tr>
<td>{{ $flight->flight_no }}</td>
<td>{{ $flight->time_departure }} - {{ $flight->time_arrival }}</td>
<td>{{ $depart_source_country }}</td>
@foreach($depart_destination_country as $destination)
<td>{{ $destination->country_name }}</td>
@endforeach
@for($y=$counter1; $y<@count($first_durations); $y++)
@php $duration_1 = $first_durations[$y]; @endphp
@break;
@endfor
<td> {{ $duration_1 }} Hours</td>
@for($df=$counter1; $df<@count($departing_flight_types); $df++)
@php $flight_type_name = $departing_flight_types{$df}; @endphp
@break;
@endfor
<td>{{$flight_type_name[0]}}</td>
@for($df=$counter1; $df<@count($departing_flight_prices); $df++)
@php $flight_type_price = $departing_flight_prices{$df}; @endphp
@break;
@endfor
@foreach($depart_destination_country as $destination)
<td>
<input type="radio" id = "flight_id" name="flight_id"
value="{{$flight->flight_id}}" required/>
@php
$total_fare = intval($book_details['seat_qty'] * ($flight_type_price[0] + $destination->country_price));
echo "PHP ". number_format($total_fare, 2, '.', ',');
@endphp
<input type="hidden" name="total_fare" value="{{$total_fare}}"/>
</td>
@endforeach
</tr>
@php
$counter1++;
@endphp
@endforeach
</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
<hr>
@if($flights_return ?? '' != null)
<div class="container">
<div class="row justify-content-center">
<div class="col-md-13">
<div class="card">
<div class="card-header bg-primary">
<i class="fas fa-plane-arrival"></i><b>
{{ __('Select your Returning Flight') }}
@foreach($flights_return ?? '' as $flight)
{{ "(".$flight->date_departure.")" }}
@break
@endforeach
</b></div>
<div class="card-body">
<form method="GET" autocomplete = "off">
@csrf
<table class="table">
<thead>
<tr>
<p style = "text-align: center">
<b>
List of flights from
{{$return_source_country}} to
@foreach($return_destination_country as $destination)
{{$destination->country_name}}
@endforeach
</b>
</p>
<th scope="col">FLIGHT NO.</th>
<th scope="col">DEPARTURE TIME / ARRIVAL TIME</th>
<th scope="col">DEPARTURE LOCATION </th>
<th scope="col">ARRIVAL LOCATION </th>
<th scope="col">FLIGHT DURATION </th>
<th scope="col">FLIGHT TYPE </th>
<th scope="col">RESERVE TICKET </th>
</tr>
</thead>
<tbody>
@php
$counter2 = 0;
$flight_type_name = '';
@endphp
@foreach($flights_return ?? '' as $flight)
<tr>
<td>{{ $flight->flight_no }}</td>
<td>{{ $flight->time_departure }} - {{ $flight->time_arrival }}</td>
<td>{{ $return_source_country }}</td>
@foreach($return_destination_country as $destination)
<td>{{ $destination->country_name }}</td>
@endforeach
@for($x=$counter2; $x<@count($second_durations); $x++)
@php $duration_2 = $second_durations[$x]; @endphp
@break;
@endfor
<td> {{ $duration_2 }} Hours </td>
@for($df=$counter2; $df<@count($returning_flight_types); $df++)
@php $flight_type_name = $returning_flight_types{$df}; @endphp
@break;
@endfor
<td>{{$flight_type_name[0]}}</td>
@for($df=$counter2; $df<@count($returning_flight_prices); $df++)
@php $flight_type_price = $returning_flight_prices{$df}; @endphp
@break;
@endfor
@foreach($return_destination_country as $destination)
<td>
<input type="radio" id = "flight_id" name="flight_id"
value="{{$flight->flight_id}}" required/>
@php
$total_fare = intval($book_details['seat_qty'] * ($flight_type_price[0] + $destination->country_price));
echo "PHP ". number_format($total_fare, 2, '.', ',');
@endphp
<input type="hidden" name="total_fare" value="{{$total_fare}}"/>
</td>
@endforeach
</tr>
@php $counter2++; @endphp
@endforeach
</tbody>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
@endif
<br><br>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-10">
<button type="submit" class="btn btn-primary">
{{ __('Continue') }}
</button>
</div>
</div>
</form>
@endsection
Here's my line of code on web.php which is responsible for routing/redirecting to a new page when Submit button was clicked:
Route::get('PassengerRegister', 'BookController@PassengerRegister')->name('PassengerRegister');
Finally the snippet source code of a function inside my controller (BookController.php):
public function PassengerRegister(Request $request){
return view("register"); //As of this moment it will just redirect to register view when submit button is clicked
}
**Question: **
Why does the form does nothing when I clicked it? and how can I fix it in order to redirect a user to register page when the submit button is clicked?
Upvotes: 0
Views: 199
Reputation: 326
As @Curstis suggested. You have several form tags scattered around this page. Now, I have removed them for you and just left the first and last form tags. So try the following code instead and the form should submit now. Always ensure your submit button is WELL bound like this: < form >...< button> ... < / button> < / form >. for it to work.
@extends('layouts.app')
@section('title', 'Select Flight')
@section('content')
<form method="GET" action="{{route('PassengerRegister')}}" autocomplete="off">
@csrf
<div class="container">
<div class="row justify-content-center">
<div class="col-md-13">
<div class="card">
<div class="card-header bg-primary">
<i class="fas fa-plane-departure"></i><b>
{{ __('Select your Departing Flight') }}
@foreach($flights_depart as $flight)
{{ "(".$flight->date_departure.")" }}
@break
@endforeach
</b></div>
<div class="card-body">
@csrf
<table class="table">
<thead>
<tr>
<p style="text-align: center">
<b>
List of flights from
{{$depart_source_country}} to
@foreach($depart_destination_country as $destination)
{{$destination->country_name}}
@endforeach
</b>
</p>
<th scope="col">FLIGHT NO.</th>
<th scope="col">DEPARTURE TIME / ARRIVAL TIME</th>
<th scope="col">DEPARTURE LOCATION </th>
<th scope="col">ARRIVAL LOCATION </th>
<th scope="col">FLIGHT DURATION </th>
<th scope="col">FLIGHT TYPE </th>
<th scope="col">RESERVE TICKET </th>
</tr>
</thead>
<tbody>
@php
$counter1 = 0;
$duration_1 = '';
$flight_type_name = '';
$flight_type_price;
$total_fare;
@endphp
@foreach($flights_depart as $flight)
<tr>
<td>{{ $flight->flight_no }}</td>
<td>{{ $flight->time_departure }} - {{ $flight->time_arrival }}</td>
<td>{{ $depart_source_country }}</td>
@foreach($depart_destination_country as $destination)
<td>{{ $destination->country_name }}</td>
@endforeach
@for($y=$counter1; $y<@count($first_durations); $y++) @php $duration_1=$first_durations[$y]; @endphp @break; @endfor <td> {{ $duration_1 }} Hours</td>
@for($df=$counter1; $df<@count($departing_flight_types); $df++) @php $flight_type_name=$departing_flight_types{$df}; @endphp @break; @endfor <td>{{$flight_type_name[0]}}</td>
@for($df=$counter1; $df<@count($departing_flight_prices); $df++) @php $flight_type_price=$departing_flight_prices{$df}; @endphp @break; @endfor @foreach($depart_destination_country as $destination) <td>
<input type="radio" id="flight_id" name="flight_id" value="{{$flight->flight_id}}" required />
@php
$total_fare = intval($book_details['seat_qty'] * ($flight_type_price[0] + $destination->country_price));
echo "PHP ". number_format($total_fare, 2, '.', ',');
@endphp
<input type="hidden" name="total_fare" value="{{$total_fare}}" />
</td>
@endforeach
</tr>
@php
$counter1++;
@endphp
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<hr>
@if($flights_return ?? '' != null)
<div class="container">
<div class="row justify-content-center">
<div class="col-md-13">
<div class="card">
<div class="card-header bg-primary">
<i class="fas fa-plane-arrival"></i><b>
{{ __('Select your Returning Flight') }}
@foreach($flights_return ?? '' as $flight)
{{ "(".$flight->date_departure.")" }}
@break
@endforeach
</b></div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<p style="text-align: center">
<b>
List of flights from
{{$return_source_country}} to
@foreach($return_destination_country as $destination)
{{$destination->country_name}}
@endforeach
</b>
</p>
<th scope="col">FLIGHT NO.</th>
<th scope="col">DEPARTURE TIME / ARRIVAL TIME</th>
<th scope="col">DEPARTURE LOCATION </th>
<th scope="col">ARRIVAL LOCATION </th>
<th scope="col">FLIGHT DURATION </th>
<th scope="col">FLIGHT TYPE </th>
<th scope="col">RESERVE TICKET </th>
</tr>
</thead>
<tbody>
@php
$counter2 = 0;
$flight_type_name = '';
@endphp
@foreach($flights_return ?? '' as $flight)
<tr>
<td>{{ $flight->flight_no }}</td>
<td>{{ $flight->time_departure }} - {{ $flight->time_arrival }}</td>
<td>{{ $return_source_country }}</td>
@foreach($return_destination_country as $destination)
<td>{{ $destination->country_name }}</td>
@endforeach
@for($x=$counter2; $x<@count($second_durations); $x++) @php $duration_2=$second_durations[$x]; @endphp @break; @endfor <td> {{ $duration_2 }} Hours </td>
@for($df=$counter2; $df<@count($returning_flight_types); $df++) @php $flight_type_name=$returning_flight_types{$df}; @endphp @break; @endfor <td>{{$flight_type_name[0]}}</td>
@for($df=$counter2; $df<@count($returning_flight_prices); $df++) @php $flight_type_price=$returning_flight_prices{$df}; @endphp @break; @endfor @foreach($return_destination_country as $destination) <td>
<input type="radio" id="flight_id" name="flight_id" value="{{$flight->flight_id}}" required />
@php
$total_fare = intval($book_details['seat_qty'] * ($flight_type_price[0] + $destination->country_price));
echo "PHP ". number_format($total_fare, 2, '.', ',');
@endphp
<input type="hidden" name="total_fare" value="{{$total_fare}}" />
</td>
@endforeach
</tr>
@php $counter2++; @endphp
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endif
<br><br>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-10">
<button type="submit" class="btn btn-primary">
{{ __('Continue') }}
</button>
</div>
</div>
</form>
@endsection
Upvotes: 0
Reputation: 334
Here is a similar post. It discusses forms with Get methods and actions, that may be your issue. The other solution would be to change this to a JavaScript method by adding a function to your form like this. However, keep in mind this post is for submitting forms and not resetting the page
Upvotes: 0