Request values of contoller not getting value of select - laravel

This is a noob question, I send a post request to my controller and all it can get is the request of the input. What I want is I can also get the value of $cat array.
Here's my blade:
#if (!$categories->isEmpty())
<form action="{{route('subcategory.store')}}" method="POST">
#csrf
<div class="row">
<div class="input-group mb-3 col-md-4">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Choose Category:</label>
</div>
<select class="custom-select" id="inputGroupSelect01">
#foreach ($categories as $cat)
<option value="{{$cat->id}}">{{$cat->name}}</option>
#endforeach
</select>
</div>
<input type="text" name="subcat" id="subcat" class="form-control col-md-3 ml-5">
<button type="submit" class="btn btn-success btn-lg ml-3">Save Sub Category</button>
</div>
</form>
#endif
And here's my returned value.
{"_token":"XlzwIt2jFqcybqqSjwLLJIAChG5tui7gvHzlaeAq","subcat":"xx"}

You forgot to add name="cat" in select i guess
<select class="custom-select" id="inputGroupSelect01">
simple add name="" attr
<select class="custom-select" id="inputGroupSelect01" name="cat">

Related

Add or delete rows in table in Thymeleaf

I wish to add row or rows into "bin type" in example below:
It depends on me how many rows it is going to be. If i will decide on three rows i wish to finalize on confirmation button and continue another table-row. I wish to do that in Thymeleaf because i don't know JavaScript. My whole project is in Spring/Hibernate/thymeleaf, contains about 40 bins in my sql DB.
Here is my html file:
<div class="form-row">
<div class="form-group col-md-8">
<select class="form-control" th:field="*{binsFeatures}">
<option value="0">Select BIN type</option>
<option th:each="binFeature : ${binsFeatures}" th:value="${binFeature.id}"
th:text="${binFeature.name}"></option>
</select>
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-dumpster"></i></span>
</div>
</div>
<div class="form-group col-md-4">
<input type="text" th:field="*{quantity}"
class="form-control input-lg"
placeholder="amount"
required="true">
<span th:if="${#fields.hasErrors('quantity')}"
th:errors="*{quantity}"
class="text-danger">
Quantity Error
</span>
<span class="input-group-addon"></span>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-8">
<select class="form-control" th:field="*{type}">
<option value="0">Select Type of Inbound</option>
<option th:each="inbound : ${inbounds}" th:value="${inbound.id}"
th:text="${inbound.type}"></option>
</select>
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-viruses"></i></span>
</div>

print result after submitting in laravel

how can I create a submit button that can show the pdf result of my form to print it directly?
this is my code below
<form method="post" action="{{ url('dashboard/generate') }}" enctype="multipart/form-data" id="form-ui">
{{ csrf_field() }}
<div class="col-md-6 col-xs-12">
<label for="exampleInputEmail1">Distributor</label>
<select name="distributor" id="type" class="form-control">
<option value="">Choose Distributor</option>
#foreach ($distributor as $item)
<option value="{{ $item->id }}">{{ $item->name }}</option>
#endforeach
</select>
</div>
<div class="col-md-6 col-xs-12">
<label for="exampleInputEmail1">Select Event</label>
<select name="event" id="type" class="form-control">
<option value="">Choose Event</option>
#foreach ($event as $item)
<option value="{{ $item->id }}">({{ $item->events->date }}, {{ $item->time }}, {{ $item->events->stage }})-{{ $item->title }}</option>
#endforeach
</select>
</div>
<div class="col-md-12 col-xs-12" style="margin-top: 10px;">
<button class="btn btn-success" type="submit" onclick="myFunction()">SUBMIT</button>
</div>
</form>
<script>
function myFunction() {
window.print();
}
</script>
but it just print the current page (the form page). any advice i can try?
try this onsubmit jquery event
<div class="col-md-12 col-xs-12" style="margin-top: 10px;">
<button class="btn btn-success" type="submit" name="submit">SUBMIT</button>
</div>
<script>
$(document).ready(function(){
$('body').on('submit', '.formsubmit', function(e) {
alert(1);
});

button not responding laravel

i have this page where i have form where the action url are same. My second form work perfectly fine but mu first form doesn't responding when i hit the button or <a>. I've try to switch the <form action="{{url('purchase')}}" method="post") between form, i've try to cut the action on second form and move it to first form still no luck... any idea? here's sum of my code
<form class="px-2 py-2" action="{{ url('purchase') }}" method="post">
{{csrf_field()}}
<div id="items">
</div>
<div class="row mx-1 px-2">
Purchase
</div>
</form>
that's my first form, inside of id="items" purposely empty since i fill it up with javascript
<form id="newItemForm" style="display:none;">
<div class="form-group row" id="item">
<label for="invoice" class="col-sm-2 col-form-label">Supplier</label>
<div class="col-sm-2">
<select class="form-control" onchange="newExisting(this)">
<option value="#" selected>Choose Supplier</option>
<option value="existing">Existing Supplier</option>
<option value="new">New Supplier</option>
</select>
</div>
<div class="col-sm-8" id="existingCompany" style="display:none;">
<div class="row">
<div class="col-sm-4">
<select class="form-control" name="fromE" onchange="localImport(this)">
<option value="#" checked>From</option>
<option value="f" checked>Import</option>
<option value="l" checked>Local</option>
</select>
</div>
<div class="col-sm-8">
<select class="form-control" name="supplier" id="supplierID">
<option value="#">Choose Company</option>
</select>
</div>
</div>
</div>
<div class="col-sm-8" style="display:none;" id="newCompany">
<div class="row">
<div class="col-sm-4">
<select class="form-control" name="fromN">
<option value="#" checked>From</option>
<option value="f" checked>Import</option>
<option value="l" checked>Local</option>
</select>
</div>
<div class="col-sm-4">
<input type="text" name="kind" value="" placeholder="PT, CV, FIRMA" class="form-control">
</div>
<div class="col-sm-4">
<input type="text" name="supplierName" placeholder="Company Name" class="form-control">
</div>
</div>
</div>
</div>
<div id="newItems">
<div class="form-group row" id="item">
<label for="invoice" class="col-sm-2 col-form-label">Item Name</label>
<div class="col-sm-10">
<input type="text" name="item0" class="form-control" placeholder="Item Name" onkeyup="getCompanyGoods(this)">
<span class="text text-danger" style="display:none;" id="existsWarning0">*Item already exists</span>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="taxInvoice">QTY<span class="text-danger">*</span></label>
<input type="number" name="qty0" class="form-control" id="qty0" required onkeyup="calculate(this)">
</div>
<div class="form-group col-md-3">
<label for="inputPassword4">Units<span class="text-danger">*</span></label>
<input type="number" name="units0" class="form-control" id="units0" required onkeyup="calculate(this)">
</div>
<div class="form-group col-md-3">
<label for="inputPassword4">Total</label>
<div class="form-controll font-weight-bold" style="font-size:x-large;" id="total0">IDR0.00</div>
</div>
</div>
</div>
<label class="btn btn-primary" id="newRow" onclick="addRow()">+ Item</label>
<input type="hidden" name="type" value="new">
<input type="hidden" name="nore" value="#" id="nore">
<input type="number" name="totalItem" value="0" id="totalItem">
<button name="button" class="btn btn-danger float-right" >Purchase</button>
</form>
this is my second form and it work perfectly....
Change
Purchase
to
<button type='submit'>Purchase</button>
Because you have used a tag instead of button type "submit"
Purchase
Change it to like this
<button class="btn btn-primary" type="submit"> Purchase </button>

Laravel - Request does not contain my inputs

I have the following form :
<div class="container text-center search-container">
<form id="search-form" action="" method="post">
<div class="nopadding col-xs-12 col-sm-2">
<select name="huge" class="form-control input-block-level selectpicker search-selector" data-style="btn-default btn-fill btn-block">
<option disabled>Search in...</option>
<option value="1" selected>foo1</option>
<option value="2">foo2</option>
<option value="3">foo3</option>
</select>
</div>
<div class="nopadding col-xs-12 col-sm-8">
<input type="text" class="form-control input-block-level search-bar" id="searchbar">
</div>
{{ csrf_field() }}
<div class="nopadding col-xs-12 col-sm-2">
<button class="btn btn-info btn-fill search-button input-block-level" type="submit">Search</button>
</div>
</form>
</div>
I use bootstrap-select for the select element.
This calls a method in my controller, however when I do a dd($request->all(), here is what I do obtain :
array:2 [▼
"huge" => "1"
"_token" => "somethingReallyLongAndBoring"
]
Basically, I am not able to retrieve my inputs. Any idea what I did wrong ?
You have to add name attribute to the input field.
<input type="text" class="form-control input-block-level search-bar" id="searchbar" name="searchbar">

Only retrieving last option in multiple select element

The form is posted and I'm retrieving the inputs with:
$inputs = Input::all();
return Response::json($inputs);
The form is like this:
<form role="form" method="POST" action="/account/enrollments/{{ $activity->id }}/update" class="form-horizontal" autocomplete="off">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-xs-12 col-md-4">
<h4>Available Students</h4>
<select multiple class="form-control" name="available">
#foreach ($available as $student)
<option value="{{ $student->id }}">{{ $student->firstname }} {{ $student->lastname }}</option>
#endforeach
</select>
</div>
<div class="col-xs-12 col-md-4 push-top">
<button name="enrol" class="btn btn-block btn-effect-ripple btn-primary">Enrol Student(s)</button>
<button name="unenrol" class="btn btn-block btn-effect-ripple btn-warning">Remove Student(s)</button>
</div>
<div class="col-xs-12 col-md-4">
<h4>Currently Enrolled Students</h4>
<select multiple class="form-control" name="enrolled">
#foreach ($enrolled as $student)
<option value="{{ $student->id}}">{{ $student->firstname }} {{ $student->lastname }}</option>
#endforeach
</select>
</div>
</div>
</form>
But the response only shows the id of the last one selected. So, if I select three from the available select, it only returns the id of the last one, like this:
{
"_token": "KOqUu3m0uxwNxPC1BVisFT2y6P86z3uoBqZiEgTa",
"available": "5",
"enrol": ""
}
How do I retrieve all three inputs?
Here's the actual HTML from source:
<form role="form" method="POST" action="/account/enrollments/1/update" class="form-horizontal" autocomplete="off">
<input type="hidden" name="_token" value="KOqUu3m0uxwNxPC1BVisFT2y6P86z3uoBqZiEgTa">
<div class="row">
<div class="col-xs-12 col-md-4">
<h4>Available Students</h4>
<select multiple class="form-control" name="available">
<option value="2">Student 2</option>
<option value="4">Student 4</option>
<option value="5">Student 5</option>
</select>
</div>
<div class="col-xs-12 col-md-4 push-top">
<button name="enrol" class="btn btn-block btn-effect-ripple btn-primary">Enrol Student(s)</button>
<button name="unenrol" class="btn btn-block btn-effect-ripple btn-warning">Remove Student(s)</button>
</div>
<div class="col-xs-12 col-md-4">
<h4>Currently Enrolled Students</h4>
<select multiple class="form-control" name="enrolled">
<option value="3">Student 3</option>
</select>
</div>
</div>
</form>
It seems that you have to put[] in the name value:
name="available[]"
Then it returns an array.

Resources