I wanted that when the user will choose which brand the model choices will also show by brand. My question is how can I get the model name base on the chosen brand when It won't show because I needed the response from the first one.
<div class="col-sm">
<form class="needs-validation" method="post" novalidate>
<div class="form-row">
<div class="col-md-6 mb-10">
<label for="validationCustom03">Select Brand</label>
<select class="form-control custom-select" name="brandname" required>
<option value="">Select Brand</option>
<?php
$ret=mysqli_query($con,"select brandName from tbl_brand");
while($row=mysqli_fetch_array($ret))
{?>
<option value="<?php echo $row['brandName'];?>" ><?php echo $brandnameSelect = $row['brandName'];?></option>
<?php } ?>
</select>
<div class="invalid-feedback">Please select Item.</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-10">
<label for="validationCustom03">Model</label>
<select class="form-control custom-select" name="modelname" required>
<option value="">Select Model</option>
<?php
$ret=mysqli_query($con,"select modelName from tbl_model WHERE brandID='$brandnameSelect'");
while($row=mysqli_fetch_array($ret))
{?>
<option value="<?php echo $row['modelName'];?>" ><?php echo $row['modelName'];?></option>
<?php } ?>
</select>
<div class="invalid-feedback">Please select Item.</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-10">
<label for="validationCustom03">Item Name</label>
<input type="text" class="form-control" id="validationCustom03" placeholder="Brand Name" name="brandname" required>
<div class="invalid-feedback">Please provide a valid item name.</div>
</div>
</div>
<button class="btn btn-primary" type="submit" name="submit">Submit</button>
</form>
</div>
</div> ```
you must use javascript and you have just 2 choices :
fetch all models when you are loading the form page, then handle their corresponding select boxes options by js based on the selected model.
use ajax on brands select boxes changes event, fetch related model and add them as options to models select box.
you cannot do anything more to achieve this.
Related
i have been making a crud application using php , mysql and bootstrap. everything is working fine but when i click on edit option the model does not open.i can understand why this is happening.
this is happening when i click on edit button. no modal is showing
Bootstrap modal not showing
code of edit button
<span class="glyphicon glyphicon-edit" style="color: #fff;"></span>
modal code
<div class="modal fade" id="edit<?php echo $row['userid']; ?>" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<center><h4 class="modal-title" id="myModalLabel">Edit</h4></center>
</div>
<div class="modal-body">
<?php
$edit=mysqli_query($conn,"select * from customer_record where userid='".$row['userid']."'");
$erow=mysqli_fetch_array($edit);
?>
<div class="container-fluid">
<form method="POST" action="edit.php?id=<?php echo $erow['userid']; ?>">
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>NAME</label>
<input type="text" name="name" class="form-control" value="<?php echo $erow['name']; ?>">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>PHONE</label>
<input type="text" name="phone" class="form-control" value="<?php echo $erow['phone']; ?>" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>PRODUCT</label>
<input type="text" name="product" class="form-control" value="<?php echo $erow['product']; ?>" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>CLIENT NAME</label>
<select type="text" name="client" class="form-control" value="<?php echo $erow['client']; ?>">
<option>select</option>
<option> Carrefour FORT - L </option>
<option> Carrefour EMP - L </option>
<option> Carrefour PKJS - L </option>
<option> Carrefour LYPR - F </option>
<option> Carrefour WTC - I</option>
<option> Carrefour PAL - K</option>
<option> Carrefour L.ONE -K</option>
<option> Hyundai </option>
<option> Kenwood </option>
<option> Canon </option>
<option> Cash </option>
<option> Multynet </option>
<option> Panasonic</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>ADDRESS</label>
<input type="text" name="address" class="form-control" value="<?php echo $erow['address']; ?>">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>ZONE AREA</label>
<select name="zone_area" class="form-control" value="<?php echo $erow['zone_area']; ?>">
<option>select</option>
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
<option>E</option>
<option>F</option>
<option>G</option>
<option>H</option>
<option>I</option>
<option>J</option>
<option>NA</option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>DELIVERY DATE</label>
<input type="date" name="delivery_date" class="form-control" value="<?php echo $erow['delivery_date']; ?>">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>DELIVERY STATUS</label>
<select name="delivery_status" class="form-control" value="<?php echo $erow['delivery_status']; ?>">
<option>select</option>
<option> Self Carry </option>
<option> Pending </option>
<option> Lift Back</option>
<option> Deliverd</option>
<option> Deliverd in 2nd attempt</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>INVOICE #</label>
<input type="text" name="invoice" class="form-control" value="<?php echo $erow['invoice']; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>VEHICLE #</label>
<select type="text" name="vehicle" class="form-control" value="<?php echo $erow['vehicle']; ?>">
<option>select</option>
<option> RIN - 4546 </option>
<option> LES - 2200 </option>
<option> LES - 8732 </option>
<option> LES - 5884 </option>
<option> LES - 4964 </option>
<option> LES - 2150 </option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>COUPAN #</label>
<input type="text" name="coupan" class="form-control" value="<?php echo $erow['coupan']; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>INSTALLER NAME</label>
<input type="text" name="installername" class="form-control" value="<?php echo $erow['installername']; ?>">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Installation Date</label>
<input type="date" name="installationdate" class="form-control" value="<?php echo $erow['installationdate']; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>INSTALLATION STATUS</label>
<select name="installationstatus" class="form-control" value="<?php echo $erow['installationstatus']; ?>">
<option>select</option>
<option>PROCESSED</option>
<option>COMPLETED</option>
<option>FAILED</option>
<option>Installed in 2nd Attempt</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Remarks ( Delivery + installation )</label>
<input type="text" id="remarks" name="remarks" class="form-control" value="<?php echo $erow['remarks']; ?>">
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
<button type="submit" class="btn btn-warning"><span class="glyphicon glyphicon-check"></span> Save</button>
</div>
</form>
</div>
</div>
</div>
the plugins i used
The following article is an answer to a similiar question, you might wanna take a look: https://stackoverflow.com/a/16095583/12739653
If it didn't help you. Please provide some general information; Did you import all required files, what's your Bootstrap version?
If you're using Bootstrap 5, you might need to use data-bs-target and data-bs-toggle instead. Learn more here: https://getbootstrap.com/docs/5.0/components/modal/#live-demo
Just make sure that your <div class="modal fade" ...> is inside the <body>.
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>
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'.
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
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