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.
Related
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>
I have a form to submit add salarie, the problem here if I delete the function store in controller, it even gives me error instead of giving me error function store does not exist.
SalarieController.php
public function store(request $request){
Salarie::create($request->all());
session()->flash('success','salarie add successfully');
return redirect('salaries');
}
web.php
Route::resource('salaries', 'SalarieController');
create.blade.php
<form action="{{ url('salaries') }}" method="post">
{{ csrf_field() }}
<div class="col-md-12">
<div class="form-group col-md-3 #if($errors->get('matricule')) has-error #endif">
<input type="text" name="matricule" class="form-control" value="{{ old('matricule') }}" placeholder="matricule">
</div>
<div class="form-group col-md-3 #if($errors->get('nom')) has-error #endif">
<input type="text" name="nom" class="form-control" value="{{ old('nom') }}" placeholder="nom">
</div>
<div class="form-group col-md-3 #if($errors->get('prenom')) has-error #endif">
<input type="text" name="prenom" class="form-control" value="{{ old('prenom') }}" placeholder="prenom">
</div>
<div class="form-group col-md-3 #if($errors->get('cin')) has-error #endif">
<input type="text" name="cin" class="form-control" value="{{ old('cin') }}" placeholder="cin">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3 ">
<input type="date" name="daten" class="form-control" value="{{ old('daten') }}" placeholder="date naissance">
</div>
<div class="form-group col-md-3">
<select class="form-control" name="situationf">
<option>celebataire</option>
<option>marie</option>
</select>
</div>
<div class="form-group col-md-3">
<input type="text" name="nbree" class="form-control" value="{{ old('nbree') }}" placeholder="nombre d'enfant">
</div>
<div class="form-group col-md-3">
<input type="text" name="cnss" class="form-control" value="{{ old('cnss') }}" placeholder="matricule CNSS">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3 #if($errors->get('salairenet')) has-error #endif">
<input type="text" name="salairenet" class="form-control" value="{{ old('salairenet') }}" placeholder="salaire net">
</div>
<div class="form-group col-md-3 #if($errors->get('unite')) has-error #endif">
<select class="form-control" name="unite">
<option>Heure</option>
<option>Jour</option>
<option>Mois</option>
</select>
</div>
<div class="form-group col-md-3">
<input type="text" name="hs" class="form-control" value="{{ old('hs') }}" placeholder="tarif HS">
</div>
<div class="form-group col-md-3">
<input type="date" name="datee" class="form-control" value="{{ old('datee') }}" placeholder="date embouche">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3">
<select class="form-control" name="fonction_id">
<option></option>
#foreach($fonctions as $fonction)
<option value="{{ $fonction->id }}">{{ $fonction->fonction}}</option>
#endforeach
</select>
</div>
<div class="form-group col-md-3">
<input type="text" name="primer" class="form-control" value="{{ old('primer') }}" placeholder="prime rendement">
</div>
<div class="form-group col-md-3">
<input type="text" name="primel" class="form-control" value="{{ old('primel') }}" placeholder="prime de longement">
</div>
<div class="form-group col-md-3">
<input type="text" name="primet" class="form-control" value="{{ old('primet') }}" placeholder="prime de transport">
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-3">
<select class="form-control" name="chantier_id">
<option></option>
#foreach($chantiers as $chantier)
<option value="{{ $chantier->id }}">{{ $chantier->chantier}}</option>
#endforeach
</select>
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-2 col-md-offset-5">
<button type="submit" class="btn btn-theme btn-lg" value="submit">Ajouter</button>
</div>
</div>
</form>
Salarie.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Salarie extends Model
{
public function chantier(){
return $this->belongsTo('App\Chantier');
}
protected $guarded = [];
}
I guess you're missing some options values
here
<select class="form-control" name="situationf">
<option>celebataire</option> // must be <option value="celeb_value">celebataire</option>
<option>marie</option> // must be <option value="marie_value">celebataire</option>
</select>
here also
<select class="form-control" name="unite">
<option>Heure</option> // must be <option value="heure_value">Heure</option>
<option>Jour</option> // must be <option value="jour_value">Jour</option>
<option>Mois</option> // must be <option value="mois_value">Mois</option>
</select>
here too
<select class="form-control" name="fonction_id">
<option></option> // remove empty option or set function_id to nullable
#foreach($fonctions as $fonction)
<option value="{{ $fonction->id }}">{{ $fonction->fonction}}</option>
#endforeach
</select>
and here
<select class="form-control" name="chantier_id">
<option></option> // same as function_id
#foreach($chantiers as $chantier)
<option value="{{ $chantier->id }}">{{ $chantier->chantier}}</option>
#endforeach
</select>
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);
});
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">
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">