Page 404 not found laravel 8 - php

i am trynig to insert data in database when i click submit button it returns 404 not found
here is the controller
function ajouterfrm()
{
return view('dashboards.directeur.ajouter');
}
function add(Request $request)
{
$request->input();
}
and here is the routes
Route::get('rapport/ajouter',[DirecteurController::class,'ajouterfrm'])->name('directeur.ajouter');
Route::post('add',[DirecteurController::class,'add'])->name('directeur.add');
my html :
here is my html
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3" style="margin-top: 50px">
<h4>Ajouter Rapport</h4>
<hr>
<form action="add" method="POST">
<input type="text" name="data_1" required>
<input type="text" name="data_2" required>
<!-- others inputs and selects ... -->
</form>
</div>
</div>
</div>
i tried to unname the last route but without any results
any suggestions ?
thanks

Your form should look like this :
<form action="{{ route('directeur.add') }}" method="post">
#csrf // for preventing forgery token attacks otherwise you will get an "419 error"
<your inputs ...>
<form>
bonne chance.

Your add route doesn't do anything at this point, so no view or response is returned for the request.
You need to return something from your controller. Please see:
https://laravel.com/docs/8.x/responses
But for now you can try in your add function
return response('test');

here is my html
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3" style="margin-top: 50px">
<h4>Ajouter Rapport</h4>
<hr>
<form action="add" method="POST">
<div class="form-group">
<label for="">Titre</label>
<input type="text" name="titre" class="form-control" placeholder="Entrer le titre du rapp">
</div>
<div class="form-group">
<label for="">Description</label>
<textarea name="description" class="form-control" rows="3" placeholder="Entrer la description ici...">
</textarea>
</div>
<div class="form-group">
<label for="">Médecin</label>
<select class="form-control" name="medecin" id="">
<option value="med">Médecin 1</option>
<option value="med">Médecin 2</option>
<option value="med">Médecin 3</option>
</select>
</div>
<div class="form-group">
<label for="">Patient</label>
<select class="form-control" name="patient" id="">
<option value="pat">Patient 1</option>
<option value="pat">Patient 2</option>
<option value="pat">Patient 3</option>
</select>
</div>
<br>
<button type="submit" class="btn btn-primary btn-block">Ajouter</button>
</form>
</div>
</div>
</div>

Related

Laravel 8 - Submit button not working with multiple forms

I'm trying to use a submit button that creates a registry (Memo) and it's products asociated to that Memo, however, I cannot get this to work.
I think it might be because I have a form inside another form. However I believe since my submit button its outside the inner form, should still work (it worked before).
I'll put my create.blade.php code below:
<form method="post" action="{{ route('memos.store') }}">
<div class="form-group">
#csrf
<label for="lbl_memo_attendant" id="lbl_memo_attendant"><strong>Solicitante:</strong></label>
<input type="text" class="form-control" name="memo_petitioner" value="{{ Auth::user()->name }}" readonly="readonly"/>
</div>
<div class="form-group">
<label for="lbl_attendant_department"><strong>Departamento solicitante:</strong></label>
<input type="text" class="form-control" name="memo_petitioner_department" value="{{ Auth::user()->department }}" readonly="readonly"/>
</div>
<div class="form-group">
<label for="lbl_product_type" name="lbl_memo_product_type"><strong>Tipo de solicitud:</strong></label></br>
<select name="memo_product_type">
<option value="Bienes" selected>Bienes</option>
<option value="Servicio">Servicio</option>
</select>
</div>
<div class="form-group">
<label for="lbl_program" name="lbl_memo_program"><strong>Programa:</strong></label></br>
<select name="memo_program">
<option value="Hospital Williams" selected>Hospital Williams</option>
<option value="Gasto Operacional DSSM">Gasto Operacional DSSM</option>
<option value="Cadi Umag">Cadi Umag</option>
</select>
</div>
<div class="container">
<h2 align="center">Ingresar productos:</h2>
<form name="add_name" id="add_name" action="{{ route('products.store') }}">
<div class="form-group">
<div class="alert alert-danger print-error-msg" style="display:none">
<ul></ul>
</div>
<div class="alert alert-success print-success-msg" style="display:none">
<ul></ul>
</div>
<div class="table-responsive">
<table class="table table-bordered" id="dynamic_field">
<tr>
<td class="col-6"><input type="text" name="product_name" placeholder="Producto" class="form-control name_list" /></td>
<td><label>Unidad:</label>
<select>
<option value="Unidad" selected>Unidad</option>
<option value="Cajas">Cajas</option>
<option value="Global">Global</option>
</select>
</td>
<td><input placeholder="Cantidad" type="number" name="product_qty"></input></td>
<td><button type="button" name="add" id="add" class="btn btn-success">Agregar otro producto</button></td>
</tr>
</table>
</div>
</form>
</div>
</div>
<div class='div-btn-create'>
<button type="submit" class="btn btn-success" id="btn_create_memo">Crear memorando</button>
</div>
</form>
HTML does not support nested forms, so the browser turns them into one. Which is why your button is outside the form. Remove the nested form and everything will work.

How to use html div tag and php to interact with the mysql database

I am using an html with div tag to do a booking system asking user input for city, date, and pet type then check the criteria from users to the SQL database, I know how to deal with just html but I am totally lost when dealing with html div tags.
Can anyone show me how to take the user inputs (city, date, and pet type) using php in the right place so i can pass it to the database to check
<div class="form-group">
<span class="form-label">Where do you work? </span>
<input class="form-control" type="text" placeholder="Please enter your city">
</div>
<!-- date picker -->
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Please take care of my pet on</span>
<input class="form-control" type="date", id="pickup" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Pet?</span>
<select class="form-control">
<option>Cat</option>
<option>Dog</option>
<option>Others</option>
</select>
<span class="select-arrow"></span>
</div>
</div>
</div>
<div class="form-btn">
<button class="submit-btn">Check availability</button>
</div>
First of all, your inputs ,buttons,select,radio buttons..etc must be inside a form tag
<form method="post/get" action="file.php">
Secondly, all your inputs need to have a name to retrieve their values. For exemple :
<input type="text" name="firstname">
And finally, it's better to giver every option in select tag a value:
<select class="form-control" name="pet">
<option value="cat">Cat</option>
<option value="dog">Dog</option>
<option value="others">Others</option>
</select>
Changed work :
<form method="post" action"file.php">
<div class="form-group">
<span class="form-label">Where do you work? </span>
<input class="form-control" type="text" placeholder="Please enter your city" name="city">
</div>
<!-- date picker -->
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Please take care of my pet on</span>
<input class="form-control" type="date", id="pickup" name="pickup" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Pet?</span>
<select class="form-control" name="pet">
<option value="cat">Cat</option>
<option value="dog">Dog</option>
<option value="others">Others</option>
</select>
<span class="select-arrow"></span>
</div>
</div>
</div>
<div class="form-btn">
<button class="submit-btn">Check availability</button>
</div>
</form>
In your file.php you need to retrieve data with $_POST :
<?php
$city=$_POST['city'];
$date=$_POST['pickup'];
$pet=$_POST['pet'];
?>
First of all, you have to wrap all this code in <form></form> tag:
<form method="post" action="path_to_your_php_handler">
<div class="form-group">
<!-- other stuff -->
<button type="submit" class="submit-btn">Check availability</button>
</div>
</form>
Also, all your inputs should have an unique attribute name, like <input class="form-control" type="date", id="pickup" name="date" required>
Than, in your php file, you can find your input values in array $_POST, like $_POST['date'] from the input with name 'date'.

how to use different forms in one blade file in laravel 5.6

I am using laravel 5.6 and I am developing auto classifieds web application. in My app I have 3 different vehicle categories as car, van, truck and I have blade file to select this three different vehicle types. when I select this vehicles my urls show like this,
http://localhost:8000/post-ad/Truck/8 <- this is category id
http://localhost:8000/post-ad/van/7
http://localhost:8000/post-ad/Car/5
now when I clicked one of above vehicle category page redirect to show.blade.php file, so, now I need 3 different forms to submit data to each vehicles, this is my vehicles form, car form
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" id="cid" name="cid" value="{{ $catagories->id }}" />
<div class="form-group">
<label for="exampleFormControlSelect1">District</label>
<select class="form-control" id="exampleFormControlSelect1" name="district">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Town</label>
<select class="form-control" id="exampleFormControlSelect1" name="town">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Brand</label>
<select class="form-control" id="exampleFormControlSelect1" name="brand">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Model</label>
<select class="form-control" id="exampleFormControlSelect1" name="model">
</select>
</div>
</form>
van form
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" id="cid" name="cid" value="{{ $catagories->id }}" />
<div class="form-group">
<label for="exampleFormControlSelect1">District</label>
<select class="form-control" id="exampleFormControlSelect1" name="district">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Town</label>
<select class="form-control" id="exampleFormControlSelect1" name="town">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Brand</label>
<select class="form-control" id="exampleFormControlSelect1" name="brand">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Model</label>
<select class="form-control" id="exampleFormControlSelect1" name="model">
</select>
</div>
</form>
Truck Form
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" id="cid" name="cid" value="{{ $catagories->id }}" />
<div class="form-group">
<label for="exampleFormControlSelect1">District</label>
<select class="form-control" id="exampleFormControlSelect1" name="district">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Town</label>
<select class="form-control" id="exampleFormControlSelect1" name="town">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Brand</label>
<select class="form-control" id="exampleFormControlSelect1" name="brand">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Model</label>
<select class="form-control" id="exampleFormControlSelect1" name="model">
</select>
</div>
</form>
I need show each form when some user click each vehicle links on one blade file. how can I do this?
You may add name to your routes, for example:
Route::group(['prefix' => 'post-ad'], function () {
Route::get('Truck/{id}', 'TruckController#fetch')->name('track');
Route::get('Van/{id}', 'VanController#fetch')->name('van');
Route::get('Car/{id}', 'CarController#fetch')->name('car');
})
Put your form to another files like:
truck-form.blade.php
van-form.blade.php
car-form.blade.php
In your view:
#if(request()->route()->getName() = 'track')
#include('truck-form')
#elseif(request()->route()->getName() = 'van')
#include('van-form')
#elseif
#include('van-form')
#endif

Laravel testing unreachable field error when there is two forms in page

I want to test a page which has two forms in.
When I want to test one of my forms the following error occurs:
Unreachable field "count"
Which count is a field in that form (it doesn't exit in the other form). When i remove the other form completely, it works correctly but I need to have both in the page.
It's my view:
<section class="content">
<div class="row">
<div class="col-md-6">
<div class="panel panel-green">
<div class="panel-heading">
<h3 class="panel-title">
Passenger Credit Adjustment
</h3>
</div>
<div class="panel-body">
<form method="post" action="{{route('credits.passenger.post', ['id' => $passenger->id])}}">
{{csrf_field()}}
<div class="form-group">
<label for="amount">Name</label>
<input type="text" class="form-control" id="name" name="name" disabled="disabled"
title="" value="{{$passenger->fullname}}">
</div>
<div class="form-group">
<label for="amount">Credit</label>
<input type="text" class="form-control" id="cashable" name="name" title=""
disabled="disabled" value="{{number_format($credit) . ' RLS'}}">
</div>
<div class="form-group">
<label for="amount">Add/DeductAmount</label>
<input type="text" class="form-control" id="amount" name="amount">
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" name="description">
</div>
<button type="submit" class="btn btn-danger">Apply</button>
</form>
</div>
<div class="panel-heading">
<h3 class="panel-title">
<i class="livicon" data-name="money" data-loop="true" data-color="#fff"
data-hovercolor="#fff" data-size="18"></i>
Voucher
</h3>
</div>
<div class="panel-body">
<form method="post"
action="{{route('credits.rideVoucher.post', ['id' => $passenger->id])}}">
{{csrf_field()}}
<div class="form-group">
<label for="type">Type</label>
<select id="single-prepend-text" class="form-control select2" title=""
name="type">
<option value="5k">5k</option>
<option value="10k">10k</option>
<option value="20k">20k</option>
<option value="15p">15%</option>
<option value="20p">20%</option>
<option value="25p">25%</option>
<option value="30p">30%</option>
<option value="50p">50% (Max 10k)</option>
<option value="100p">100% (Max 20k)</option>
</select>
</div>
<button type="submit" class="btn btn-danger" name="generate">Generate</button>
</form>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-green">
<div class="panel-heading">
<h3 class="panel-title">
Free Ride
</h3>
</div>
<div class="panel-body">
<form method="post"
action="{{route('credits.passenger.freeRide.post', ['id' => $passenger->id])}}">
{{csrf_field()}}
<div class="form-group">
<label>Number of free ride(s):</label>
<input type="number" name="count" value="1" title="Count" id="count"
class="form-control">
</div>
<div class="form-group">
<label>Cap:</label>
<select class="form-control" name="cap" title="">
<option value="">[NOT SELECTED]</option>
<option value="50000">5,000 T</option>
<option value="100000">10,000 T</option>
<option value="150000">15,000 T</option>
<option value="200000">20,000 T</option>
</select>
</div>
<input type="submit" class="btn btn-danger" name="generate" value="Generate">
</form>
</div>
</div>
</div>
</div>
It's my test:
$this->visit($uri)
->type(3, 'count')
->select($cap, 'cap')
->press('Generate')
I'm using Laravel 5.1.
Both submit buttons have the same name. Try using different names. Also, instead of using press, you can use the submitForm method

Checked Checkbox Not Working?

I have an HTML form that posts to a PHP script. Everything is working except the checkbox. When it is checked, the value is not being posted.
HTML:
<input name="test" id="checkbox-02" type="checkbox" value="1" />
PHP:
if(!isset($_POST['test'])) {
$eventRepeat="No";
}
if(isset($_POST['test'])) {
$eventRepeat="Yes";
}
When this code runs, $eventRepeat always comes out as "No." I tried using the command "print_r($_POST)" and all inputs are posted except the checkbox, even when it is checked.
Any ideas what could cause this? I do have jQuery running so when it is checked two divs appear. Could that somehow be interfering? Here's the jQuery:
$(document).ready(function () {
$('#checkbox-02').change(function () {
if (!this.checked)
// ^
$('#repeatUntilDIV').fadeIn('slow');
$('#repeatFrequencyDIV').fadeIn('slow');
});
});
For reference, here is the full code:
<form class="cmxform form-horizontal tasi-form" id="commentForm" role="form" action="" method="post">
<div class="form-group">
<label for="inputEventTitle" class="col-lg-2 control-label">Event Title</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventTitle" placeholder="Event Title" required>
</div>
</div>
<div class="form-group">
<label for="inputEventDescription" class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventDescription" placeholder="Event Description" required>
</div>
</div>
<div class="form-group">
<label for="inputEventStartTime" class="col-lg-2 control-label">Start Time</label>
<div class="col-lg-10">
<select name="inputEventStartTime" class="form-control" id="dp1" required>
<option label="Start Time">
<option value="12:00AM">12:00AM</option>
<option value="12:15AM">12:15AM</option>
<option value="12:30AM">12:30AM</option>
<option value="12:45AM">12:45AM</option>
<option value="1:00AM">1:00AM</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEventEndTime" class="col-lg-2 control-label">End Time</label>
<div class="col-lg-10">
<select name="inputEventEndTime" class="form-control" id="dp1" required>
<option label="End Time">
<option value="1:00AM">1:00AM</option>
<option value="1:15AM">1:15AM</option>
<option value="1:30AM">1:30AM</option>
<option value="1:45AM">1:45AM</option>
<option value="2:00AM">2:00AM</option>
</select> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Date</label>
<div class="col-sm-6">
<input id="dp1" name="inputEventDate" type="text" size="16" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="inputEventDate" class="col-lg-2 control-label">Repeat?</label>
<div class="col-lg-10 checkboxes">
<label class="label_check" for="checkbox-02"> </label>
<input name="test" id="checkbox-02" type="checkbox" value="1" /> Yes, I want to repeat this event.
</div>
</div>
<div class="form-group" id="repeatUntilDIV" style="display:none;">
<label for="inputEventEndDate" class="col-lg-2 control-label">Repeat Until</label>
<div class="col-lg-10">
<input name="inputEventEndDate" id="eventEndDate" type="text" placeholder="End Date" class="form-control">
</div>
</div>
<div class="form-group" id="repeatFrequencyDIV" style="display:none;">
<label for="inputEventFrequency" class="col-lg-2 control-label">Repeat Every</label>
<div class="col-lg-10">
<select name="inputEventFrequency" class="form-control" id="dp1">
<option label="Repeat Every">
<option value="1">Repeat Every Day</option>
<option value="2">Repeat Every Other Day</option>
<option value="7">Repeat Every Week</option>
<option value="14">Repeat Every Other Week</option>
<option value="30">Repeat Every Month</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
<input type="submit" name="addPrimaryEvent" class="btn btn-success" value="Submit" />
</form>
I get this from var_dump($_POST):
array(8) {
["inputEventTitle"]=>
string(5) "Title"
["inputEventDescription"]=>
string(11) "Description"
["inputEventStartTime"]=>
string(6) "2:00AM"
["inputEventEndTime"]=>
string(6) "3:00AM"
["inputEventDate"]=>
string(10) "05-26-2014"
["inputEventEndDate"]=>
string(10) "05-29-2014"
["inputEventFrequency"]=>
string(1) "1"
["addPrimaryEvent"]=>
string(6) "Submit"
}
Very unclear why this would not work. But I noticed inconsistencies & imbalance in the HTML tags as well as an empty action="" which is not HTML5 valid. For more details, see this great answer over here.
So I have set it to #. You might want to actually change that to the full filename or path to the PHP script such as action="form.php". Or you could leave it out altogether like this:
<form class="cmxform form-horizontal tasi-form" id="commentForm" role="form" action="#" method="post">
But I prefer to be explicit & recommend the action="form.php" way of handling things. Here is your cleaned up HTML form:
<form class="cmxform form-horizontal tasi-form" id="commentForm" role="form" action="#" method="post">
<div class="form-group">
<label for="inputEventTitle" class="col-lg-2 control-label">Event Title</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventTitle" placeholder="Event Title" required="" />
</div>
</div>
<div class="form-group">
<label for="inputEventDescription" class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventDescription" placeholder="Event Description" required="" />
</div>
</div>
<div class="form-group">
<label for="inputEventStartTime" class="col-lg-2 control-label">Start Time</label>
<div class="col-lg-10">
<select name="inputEventStartTime" class="form-control" id="dp1" required="">
<option value="12:00AM">
12:00AM
</option>
<option value="12:15AM">
12:15AM
</option>
<option value="12:30AM">
12:30AM
</option>
<option value="12:45AM">
12:45AM
</option>
<option value="1:00AM">
1:00AM
</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEventEndTime" class="col-lg-2 control-label">End Time</label>
<div class="col-lg-10">
<select name="inputEventEndTime" class="form-control" id="dp1" required="">
<option value="1:00AM">
1:00AM
</option>
<option value="1:15AM">
1:15AM
</option>
<option value="1:30AM">
1:30AM
</option>
<option value="1:45AM">
1:45AM
</option>
<option value="2:00AM">
2:00AM
</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Date</label>
<div class="col-sm-6">
<input id="dp1" name="inputEventDate" type="text" size="16" class="form-control" required="" />
</div>
</div>
<div class="form-group">
<label for="inputEventDate" class="col-lg-2 control-label">Repeat?</label>
<div class="col-lg-10 checkboxes">
<input name="test" id="checkbox-02" type="checkbox" value="1" /> Yes, I want to repeat this event.
</div>
</div>
<div class="form-group" id="repeatUntilDIV" style="display:none;">
<label for="inputEventEndDate" class="col-lg-2 control-label">Repeat Until</label>
<div class="col-lg-10">
<input name="inputEventEndDate" id="eventEndDate" type="text" placeholder="End Date" class="form-control" />
</div>
</div>
<div class="form-group" id="repeatFrequencyDIV" style="display:none;">
<label for="inputEventFrequency" class="col-lg-2 control-label">Repeat Every</label>
<div class="col-lg-10">
<select name="inputEventFrequency" class="form-control" id="dp1">
<option value="1">
Repeat Every Day
</option>
<option value="2">
Repeat Every Other Day
</option>
<option value="7">
Repeat Every Week
</option>
<option value="14">
Repeat Every Other Week
</option>
<option value="30">
Repeat Every Month
</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button> <input type="submit" name="addPrimaryEvent" class="btn btn-success" value="Submit" />
</div>
</form>

Categories