Laravel - Request does not contain my inputs - laravel

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">

Related

how to make selected option using enum in laravel?

this is my code, how to make the selected option value in the edit form using enum data in the database? this is not working it just view the select option, not with id-data
this the code blade
<!-- Modal edit -->
#foreach($daftar_pelanggan as $pelanggan)
<div class="modal fade" id="editModal-{{ $pelanggan->id }}" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mb-0" id="editModalLabel">Update Data Pelanggan</h5>
</div>
<div class="modal-body">
<!-- Card body -->
<form role="form" action="{{ route('daftar_pelanggan.update') }}" method="POST" id="editForm">
#csrf
#method('PUT')
<!-- Input groups with icon -->
<div class="form-group row">
<label for="updateNamaPelanggan" class="col-md-2 col-form-label form-control-label">Nama</label>
<div class="col-md-10">
<input type="hidden" name="id" value="{{ $pelanggan->id }}">
<input class="form-control" type="nama" value="{{ $pelanggan->nama_pelanggan }}" id="updateNamaPelanggan" name="updateNamaPelanggan" required >
</div>
</div>
<div class="form-group row">
<label for="updateAlamat" class="col-md-2 col-form-label form-control-label">Alamat</label>
<div class="col-md-10">
<input class="form-control" type="alamat" value="{{ $pelanggan->alamat }}" id="updateAlamat" name="updateAlamat" required>
</div>
</div>
<div class="form-group row">
<label for="updateNoTelp" class="col-md-2 col-form-label form-control-label">No.Telp</label>
<div class="col-md-10">
<input class="form-control" type="notelp" value="{{ $pelanggan->no_telp }}" id="updateNoTelp" name="updateNoTelp" required>
</div>
</div>
<div class="form-group row">
<div class="col-md-6">
<div class="form-group">
<label class="form-control-label" for="updatePoin">POIN</label>
<input type="text" class="form-control" value="{{ $pelanggan->poin }}" id="updatePoin" name="updatePoin">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="form-control-label" for="status_member">Kategori</label>
<select class="form-control" id="status_member" name="status_member" required="required">
<option value="" disabled selected>- Pilih -</option <option value="silver"{{($pelanggan->status_member === 'silver') ? 'selected' : '' }} >Silver</option>
<option value="gold" {{ ($pelanggan->status_member === 'gold'? 'selected' : '')}}>Gold</option>
<option value="diamond" {{($pelanggan->status_member === 'diamond')? 'selected' : ''}}>Diamond</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-secondary" data-dismiss="modal">Reset</button>
<button type="submit" class="btn btn-primary">Update Data</button>
</div>
</form>
</div>
</div>
</div>
#endforeach
this is select code this is not working what's wrong with this code?
<option value="" disabled selected>- Pilih -</option <option value="silver"{{($pelanggan->status_member === 'silver') ? 'selected' : '' }} >Silver</option>
<option value="gold" {{ ($pelanggan->status_member === 'gold'? 'selected' : '')}}>Gold</option>
<option value="diamond" {{($pelanggan->status_member === 'diamond')? 'selected' : ''}}>Diamond</option>
</select>
and i edit with this still not working what's wrong with this code?
<select class="form-control" id="status_member-" name="status_member" required="required">
#if($pelanggan->status_member == "silver")
<option value="silver" selected="selected">Silver</option>
<option value="gold">Gold</option>
<option value="diamond">Diamond</option>
#elseif($pelanggan->status_member == "gold")
<option value="silver">Silver</option>
<option value="gold" selected="selected">Gold</option>
<option value="diamond">Diamond</option>
#else
<option value="silver">Silver</option>
<option value="gold" >Gold</option>
<option value="diamond" selected="selected">Diamond</option>
#endif
</select>

Request values of contoller not getting value of select

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">

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 problem with passing variables from controller to view

I am working on a laravel project and having a problem passing variables from the controller to the view:
this is the controller method:
public function index($id){
$data = [];
$company = DB::table('companies')->where('id',$id)->first();
return view('searchResultAdmin.index', ['company'=>$company, 'Data'=>$data]);
}
and this is the view :
{{ Form::open(array('url' => '/SearchResultAdmin', 'method' => 'post')) }}
<div class="radio-buttons display-inline">
<fieldset class="display-inline group1">
<label class="radio-inline">
<input type="radio" name="SearchLocation" id="value1" value="Actuals" checked>Actuals
</label>
<label class="radio-inline">
<input type="radio" name="SearchLocation" id="value2" value="Forecasts">Forecasts
</label>
</fieldset>
{{ Form::hidden('id', ($company->id)) }}
<fieldset class="display-inline">
<label class="radio-inline">
<input type="radio" name="Order" id="value3" value="Ascending" checked>Ascending
</label>
<label class="radio-inline">
<input type="radio" name="Order" id="value4" value="Descending">Descending
</label>
</fieldset>
</div>
<div class="dropdown-header-table display-inline">
<h5>Search By:
<select name="SearchBy">
<option value="Account">Account</option>
<option value="Name">Name</option>
<option value="Year">Year</option>
<option value="Description">Description</option>
<option value="Amount">Amount</option>
</select>
</h5>
</div>
<div class="search-input display-inline">
<div class="table-form-header">
<input type="text" class="form-control" name="SearchInputs" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
{{ Form::close() }}
the error says: undefined variable company on view
You get the error because of
{{ Form::hidden('id', ($company->id)) }}
Add dd($company) or dd($company->id) in your controller before the returning the view and see what you get.
Good luck!

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