i'm trying to make a timesheet table that takes inputs from attendance machine, and it can be edited later on, my table look like this:
![timesheet table][1]: https://i.stack.imgur.com/5D1ap.png
this is the popup to edit time and reason of editing the half day :
[edit time and reason][2]: https://i.stack.imgur.com/tPa37.png
however, when i pick time and reason, i can't update them in the table, this is the code of modal:
<div class="modal fade" id="change-date" tabindex="-1" role="dialog" aria-labelledby="change-dateLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="change-dateLabel">Changer l'heure</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="">
<div class="form-group">
<input type="time" class="form-control">
</div>
<div class="form-group">
<select name="motif" class="form-control">
<option value="">MCD</option>
<option value="">MTA</option>
<option value="">CA</option>
<option value="">AIR</option>
<option value="">MLD</option>
<option value="">CS</option>
</select>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
<button type="button" class="btn btn-primary">Enregistrer</button>
</div>
</div>
</div>
</div>
</div>
is there any solution to make it working?
Okay, you need a couple of things for your modal form to work.
You need to add route in your form open tag (see my example below)
Your form submit button at the modal-footer div needs to be inside the form open and close tags (see my exaple below)
Your submit button must have a type of submit for it to send to form parameters. (see my example below)
You need a method in your controller to process your form request and save into the database (Hope you know that.).
<div class="modal fade" id="change-date" tabindex="-1" role="dialog" aria-labelledby="change-dateLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
{{ Form::open(['action' => 'YourController#update_method','method' =>'PATCH']) }}
<div class="modal-header">
<h5 class="modal-title" id="change-dateLabel">Changer l'heure</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{-- <form action=""> remove --}}
<div class="form-group">
<input type="time" class="form-control">
</div>
<div class="form-group">
<select name="motif" class="form-control">
<option value="">MCD</option>
<option value="">MTA</option>
<option value="">CA</option>
<option value="">AIR</option>
<option value="">MLD</option>
<option value="">CS</option>
</select>
</div>
{{-- </form> remove --}}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
{{-- Your submit button should look like this --}}
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
{{ Form::close() }} <!-- end form -->
</div>
</div>
</div>
</div>
Also make sure the function you put on your form's action attribute is defined on your routes file like this below
Route::patch('url', 'YourController#update_method')->name('model.update_method');.
Related
Please I need your HELP...
I'm trying to send a Post request from a button using Ajax to my controller to do a create. I use laravel 9. I hope you can help me :-D
My blade____________________________________
`
Let us know a bit about Your running goals and experience so we can offer You the best training plan!
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Take a quick survey
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Runner Survey</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="POST" action="/" id="survey">
<div class="row mb-3">
<label for="level" class="col-md-4 col-form-label text-md-end">I would describe my current level of fitness as</label>
<div class="col-md-6">
<select name="level" id="level" form="survey" class="form-control" required autocomplete="new-level">
<option value="beginner">Beginner</option>
<option value="intermediate">Intermediate</option>
<option value="advanced">Advanced</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="distance" class="col-md-4 col-form-label text-md-end">The distance I want to run in km is</label>
<div class="col-md-6">
<select name="distance" id="distance" form="survey" class="form-control" required autocomplete="new-distance">
<option value="5">5</option>
<option value="10">10</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="time" class="col-md-4 col-form-label text-md-end">How many weeks do you have to achieve it?</label>
<div class="col-md-6">
<select name="time" id="time" form="survey" class="form-control" required autocomplete="new-time">
<option value="4">4</option>
<option value="8">8</option>
<option value="12">12</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button id="savebtn" type="submit" class="btn btn-primary submit" onclick="saveForm('{{ route('forms.store')}}')">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Fin Modal -->
</div>
</div>
</div>
</div>
</div>
#endsection
function saveForm(route){
const request = $.ajax({
Method: 'POST',
url: route,
}).done(function(response) {
$(#savebtn).attr('form', response);
});
}
My controller______________________________________________________
public function store(FormsRequest $request)
{
$data = $request->validated();
$name = $data['name'];
$userId= $data['user_id'];
$level= $data['level'];
$time=$data['time'];
$distance=$data['distance'];
$result = $this->formService->store($name, $userId, $level, $time, $distance);
return 'Created successfully!';
}
I need to turn in an assignment and I'm stuck...
I have a view made with bootstrap modal, but this form not send data to my controller. When print data from console I have only null values. My view is following:
modal-form
My code in the frontend is:
<!-- new modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<form th:action="#{/creconocida/addNew}" method="post">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h5 class="modal-title w-100" id="exampleModalLabel">Nueva
Comunidad Reconocida</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Código
único</span>
</div>
<input type="text" class="form-control" id="codigo"
name="codigoN" aria-describedby="basic-addon3">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon2">Nombre</span>
</div>
<input type="text" class="form-control" id="nombre"
name="nombreN" aria-describedby="basic-addon3">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon3">Número
familias</span>
</div>
<input type="number" class="form-control" id="numero"
name="numeroN" aria-describedby="basic-addon3">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Nacionalidad</label>
</div>
<select class="custom-select" id="nacionalidad"
name="nacionalidadN">
<option selected>Seleccione...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</div>
<div class="modal-footer ">
<button type="submit" class="btn btn-primary mr-auto">Guardar</button>
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</form>
</div>
Add new method in controller
#PostMapping("/addNew")
public String addNew(ComunidadReconocida creconocida) {
System.out.println("Guardando comunidad "+creconocida.getNam_m());//get only null values
asentamientoService.addNew(creconocida);
return "redirect:/creconocida/listar";
}
I can create a new entity but I can't send the values entered in the form. How could I do to capture the values and pass them to the controller
Your problem is you are not indicates to Spring that you want a '#RequestParam'.
public String addNew(#RequestParam ComunidadReconocida creconocida)
The modal gets data from the #foreach and displays them. And from the form it posts the data entered to the next POST route {{ route('user.give') }}. However, it keeps trying to perform a GET request to a different route(precisely the route just above it). Please help, thank you for helping
#section('content')
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
#if(count($orgs) > 0)
#foreach($orgs as $org)
<div class="card m-1 col-md-3 p-0">
<img class="card-img-top" src="{{ asset('storage/'.$org->logo) }}" alt="{{ $org->name }} logo" />
<div class="card-body">
<span class="card-title"><strong><i class="fa fa-church"></i> {{ $org->name }}</strong></span>
<div class="small"><i class="fa fa-exchange-alt"></i> {{ $org->alias }}</div>
<p class="card-text"></p>
<button class="btn btn-outline-primary rounded-0" data-toggle="modal" data-target="#exampleModalCenter">
<i class="fa fa-credit-card"></i>
Give
</button>
<i class="fa fa-cogs"></i>
</div>
</div>
#endforeach
#else
<p>Sorry, there's no match for your search.</p>
#endif
and right below is the modal. It is actually continuation of the code above. The modal actually comes up, the issue only occurs at the point of posting
<!-- form modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<cite>You are about to give to {{ $org->name }}</cite>
<!-- form -->
<form method="POST" action="{{ route('user.give') }}">
#csrf
<input type="hidden" name="organisation_name" value="{{ $org->name }}">
<input type="hidden" name="organisation_id" value="{{ $org->id }}">
<input type="hidden" name="organisation_email" value="{{ $org->email }}">
<input type="hidden" name="organisation_logo" value="{{ $org->logo }}">
<div class="form-group">
<label for="amount">Amount</label>
<input type="number" class="form-control rounded-0" name="amount" aria-describedby="amount" placeholder="e.g 5000" required>
</div>
<div class="form-group">
<label for="purpose">Purpose</label>
<input type="text" class="form-control rounded-0" name="purpose" placeholder="e.g tithe">
</div>
<button type="submit" class="btn btn-outline border-dark text-dark rounded-0" id="proceed">
Proceed
</button>
</form>
<!-- //form -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline border-dark text-dark rounded-0" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div>
</div>
</div>
<!-- //form modal -->
#endsection
Here are my routes
Route::middleware('auth')->group(function (){
Route::post('/user/search', 'HomeController#search')->name('user.search');
Route::post('/user/give/', 'HomeController#give')->name('user.give');
Route::get('/user/verify/{reference}', 'HomeController#verify')->name('user.verify');
It visits user.search instead of user.give and it does that with a GET
$org is not what you want in your modal: it is the last $org from your loop over your $orgs array since it is not inside the #foreach loop.
You need to generate your modal dynamically (through javaScript or other) when you click the button showing the modal.
Found it. Apparently I added a validation rule that was failing when the form was submitted. Since the validation error could not be sent to the modal it was performing a GET.
Breathing fresh air now. Thanks for your support y’all
I am trying to open multiple modals on a single page but their ids are conflicting with each other. I got this code from bootstrap-4 documentation,
Modal 1 is works fine but modal 2 fails to work, I wants that both of them to work separately
code:
modal1
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
Add New
</button>
<!-- Modal Add Owner -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Owner</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="{{ route('owner.store') }}">
#csrf
<div class="form-group">
<label for="">Add Owner Name</label>
<input type="text" name="owner_name" class="form-control" id="" placeholder="Owner Name">
</div>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
modal2:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Show
</button>
<!-- Modal Show Owner-->
<div class="modal fade" id="exampleModalshow" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabe2" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">View Owner</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="{{ route('owner.update', $owner->id) }}">
#csrf
#method('PATCH')
<div class="form-group">
<label for="">Owner Name</label>
<input type="text" name="owner_name" class="form-control" value="{{ $owner->owner_name }}">
</div>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
Change data-target on the second modal button to match the modal id
<button data-target="#exampleModalshow">
... rest of the code
</button>
I'am new to laravel. I've a sort of Restaurant Management System's dashboard.
I am showing menu on a blade. By selecting Category from dropdown its showing list of Dishes. Each Dish Which contains Dish Ingredients and Dish AddOn as well. Now I've Edit Button on each dish's Ingredient which will show the Modal against specific Dish's Ingredient. The problem is when I click the edit button, Modal Popup and it shows the Last Dish's Ingredients rather than the Dish's Ingredient which is intended to Edit.
#foreach($items as $item)
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div class="menu-block">
<div class="menu-content">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="dish-img"><img height="120px" width="120px" src="{{asset($item['image'])}}" alt="" class="img-circle"></div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
<div class="dish-content">
<h5 class="dish-title">
<b>{{$item['name']}}</b>
<i class="ft-edit"></i>
<i class="ft-trash-2"></i>
</h5>
<h6><b>Ingredients:</b></h6>
#foreach($add_ingredients as $add_ingredient)
#foreach($dish_ing as $dish_in)
#if($item['id']==$dish_in->dish_id&&$dish_in->ingredient_id==$add_ingredient['id'])
<span class="dish-meta" >/{{$add_ingredient['name']}}</span>
#endif
#endforeach
#endforeach
<i class="ft-edit"></i>Edit
<button type="button" class="btn" data-toggle="modal" data-target="#ingredient"><i class="ft-plus-square" ></i>Add</button>
<h6><b>Addons:</b></h6>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<span class="dish-meta" >/{{$add_item['name']}} </span>
#endif
#endforeach
<i class="ft-edit"></i>Edit
Modal Section:
<div class="modal fade editaddon{{$item['id']}}" id="">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form class="form form-horizontal" method="get" action="">
#csrf
<div class="form-body">
<h4 class="form-section"><i class="ft-user"></i>Dish Addon form</h4>
<div class="form-group row">
<label class="col-md-3 label-control" for="projectinput6">Category Name</label>
<div class="col-md-9">
<select id="projectinput6" name="id2" class="form-control">
<option value="none" selected="" disabled="">Select Relevant Category</option>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<option value="{{$add_item['id']}}">{{$add_item['name']}}</option>
#endif
#endforeach
</select>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
All I want is to Show the Specific Dish's Ingredient in the Modal When Editing.
Any help will highly appreciated
I have modified the snippet and added the modal box in the main foreach loop. Also i have removed the dot from the data target.
#foreach($items as $item)
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div class="menu-block">
<div class="menu-content">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="dish-img"><img height="120px" width="120px" src="{{asset($item['image'])}}" alt="" class="img-circle"></div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
<div class="dish-content">
<h5 class="dish-title">
<b>{{$item['name']}}</b>
<i class="ft-edit"></i>
<i class="ft-trash-2"></i>
</h5>
<h6><b>Ingredients:</b></h6>
#foreach($add_ingredients as $add_ingredient)
#foreach($dish_ing as $dish_in)
#if($item['id']==$dish_in->dish_id&&$dish_in->ingredient_id==$add_ingredient['id'])
<span class="dish-meta">/{{$add_ingredient['name']}}</span>
#endif
#endforeach
#endforeach
<i class="ft-edit"></i>Edit
<button type="button" class="btn" data-toggle="modal" data-target="#ingredient"><i class="ft-plus-square"></i>Add</button>
<h6><b>Addons:</b></h6>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<span class="dish-meta">/{{$add_item['name']}} </span>
#endif
#endforeach
<i class="ft-edit"></i>Edit
<div class="modal fade editaddon-{{$item['id']}}" >
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form class="form form-horizontal" method="get" action="">
#csrf
<div class="form-body">
<h4 class="form-section"><i class="ft-user"></i>Dish Addon form</h4>
<div class="form-group row">
<label class="col-md-3 label-control" for="projectinput6">Category Name</label>
<div class="col-md-9">
<select id="projectinput6" name="id2" class="form-control">
<option value="none" selected="" disabled="">Select Relevant Category</option>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<option value="{{$add_item['id']}}">{{$add_item['name']}}</option>
#endif
#endforeach
</select>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforach