I don't see "name" attribute for your place...
Mar 7, 2018
3
Level 2
How To Pass Jquery Values To PHP In Laravel
I am creating a Ticket Reservation System and I want to insert data into the Database. As usual, I used HTML form and all the data goes to the database except seat numbers. And it doesn't give me an error. For the seat numbers, I used Jquery and I want to insert that Jquery values into the database. I don't know is this possible or not. ( Seat numbers = items )
How can I Fix this ??
Here is my Seat.blade.php
<form class="form-horizontal" id="form1" method="POST" action="{{ route('seatsinsert') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="dt"> <br>
@if(session()->has('Msg'))
<h4 class="alert alert-success"> {{ session()->get('Msg') }} </h4>
@endif
<div class="form-group row">
<label for="example-date-input" class="col-2 col-form-label">Select Date :</label>
<div class="col-10">
<input class="form-control" type="date" name="date" placeholder="mm-dd-yyyy" id="example-date-input">
</div>
</div>
<div class="form-group">
<label for="exampleSelect1">Select Time :</label>
<select name="st" class="form-control" id="exampleSelect1">
<option>10.30 am</option>
<option>1.30 pm</option>
<option>4.30 pm</option>
<option>7.30 pm</option>
</select>
</div>
</div>
<h2 style="font-size:1.2em;font-family: Times New Roman;"> Choose seats by clicking below seats :</h2>
<div id="holder">
<ul id="place">
</ul>
</div>
<input type="submit" class="btn btn-primary" id="btnShowNew" value="Continue"> <br><br>
<script type="text/javascript">
$(function () {
$('#btnShowNew').click(function () {
var str = [], item;
$.each($('#place li.' + settings.selectingSeatCss + ' a'), function (index, value) {
var item = $(this).attr('title').var();
//str.push(item);
$.ajax({
type: "post",
url: "{{ route('seatsinsert') }}",
data: {items: item}
})
});
//alert(str.join(','));
})
});
</script>
</form>
Here is my SeatController.php
public function seatsinsert(Request $request) {
$date = $request->input('date');
$st = $request->input('st');
$item = $request->input('items');
//$item = item;
$user = new Seats();
$user->date = $date;
$user->st = $st;
$user->item = $item;
$this->validate($request, [
'date' => 'required'
]);
$user->save();
$request->session()->flash('Msg', 'Successfully Inserted !!');
return redirect('Seats');
}
Here are my Routes.
Route::post('seatsinsert', [
'uses' => 'SeatsController@seatsinsert',
'as' => 'seatsinsert'
]);
Please or to participate in this conversation.