I have a custom input field that acts as a drop-down menu and it works like this:
Each option is an <input> field and I need the value of this input to be passed into the controller. The <input> looks like this:
<!-- Updated -->
<label for="United States">United States</label>
<input type="radio" class="radio" id="United States" name="country" value="United States">
When the user presses the continue button, I want the value of the <input> to be passed to my controller: WelcomeController.
-- Updated --
My controller method looks like this:
public function countrySelect(Request $request)
{
$country = $request->input('country');
dd($country);
}
Here is a basic code structure of the inputs - I think I should be using a form and so have created a route in web.php:
Route::post('/', [\App\Http\Controllers\WelcomeController::class, 'countrySelect'])->name('CS');
And that the input should have the value property:
<!-- Updated -->
<form action="{{ route('CS') }}" method="POST">
<input name="country" value="[COUNTRY Value]">
<button type="submit"> CONTINUE </button>
</form>
The countrySelect method in my controller is empty and so how do I pass the value of the <input> into it? Thanks!
My Full Form:
<form action="{{ route('CS') }}" method="POST">
#csrf
<div class="country-select-container">
<div class="country-align-container">
<div class="CountryInput">
<div class="select-box">
<div class="options-container">
<div class="option">
<label for="United States">United States</label>
<input type="radio" name="country" value="United States">
</div>
<div class="option">
<label for="United Kingdom And Ireland">United Kingdom And Ireland</label>
<input type="radio" class="radio" id="United Kingdom And Ireland" name="country" value="United Kingdom And Ireland">
</div>
<div class="option">
<label for="Philippines">Philippines</label>
<input type="radio" name="country" value="Philippines">
</div>
<div class="option">
<label for="India">India</label>
<input type="radio" name="country" value="India">
</div>
<div class="option">
<label for="Indonesia">Indonesia</label>
<input type="radio" name="country" value="Indonesia">
</div>
<div class="option">
<label for="Malaysia">Malaysia</label>
<input type="radio" name="country" value="Malaysia">
</div>
<div class="option">
<label for="Mexico">Mexico</label>
<input type="radio" name="country" value="Mexico">
</div>
<div class="option">
<label for="Singapore">Singapore</label>
<input type="radio" name="Singapore">
</div>
<div class="option">
<label for="Germany">Germany</label>
<input type="radio" name="country" value="Germany">
</div>
<div class="option">
<label for="Brazil">Brazil</label>
<input type="radio" name="country" value="Brazil">
</div>
<div class="option">
<label for="Canada">Canada</label>
<input type="radio" name="country" value="Canada">
</div>
<div class="option">
<label for="Italy">Italy</label>
<input type="radio" name="country" value="Italy">
</div>
<div class="option">
<label for="Colombia">Colombia</label>
<input type="radio" name="country" value="Colombia">
</div>
<div class="option">
<label for="Australia">Australia</label>
<input type="radio" name="country" value="Australia">
</div>
<div class="option">
<label for="South Africa">South Africa</label>
<input type="radio" name="country" value="South Africa">
</div>
<div class="option">
<label for="France">France</label>
<input type="radio" name="country" value="France">
</div>
<div class="option">
<label for="Pakistan">Pakistan</label>
<input type="radio" name="country" value="Pakistan">
</div>
<div class="option">
<label for="Bangladesh">Bangladesh</label>
<input type="radio" name="country" value="Bangladesh">
</div>
<div class="option">
<label for="Spain">Spain</label>
<input type="radio" name="country" value="Spain">
</div>
<div class="option">
<label for="United Arab Emirates">United Arab Emirates</label>
<input type="radio" name="country" value="United Arab Emirates">
</div>
<div class="option">
<label for="Netherlands">Netherlands</label>
<input type="radio" name="country" value="Netherlands">
</div>
<div class="option">
<label for="Sri Lanka">Sri Lanka</label>
<input type="radio" name="country" value="Sri Lanka">
</div>
<div class="option">
<label for="Russia">Russia</label>
<input type="radio" name="country" value="Russia">
</div>
<div class="option">
<label for="Trinidad & Tobago">Trinidad & Tobago</label>
<input type="radio" name="country" value="Trinidad & Tobago">
</div>
<div class="option">
<label for="Saudi Arabia">Saudi Arabia</label>
<input type="radio" name="country" value="Saudi Arabia">
</div>
<div class="option">
<label for="Thailand">Thailand</label>
<input type="radio" name="country" value="Thailand">
</div>
<div class="option">
<label for="Peru">Peru</label>
<input type="radio" name="country" value="Peru">
</div>
<div class="option">
<label for="New Zealand">New Zealand</label>
<input type="radio" name="country" value="New Zealand">
</div>
<div class="option">
<label for="Vietnam">Vietnam</label>
<input type="radio" name="country" value="Vietnam">
</div>
<div class="option">
<label for="Japan">Japan</label>
<input type="radio" name="country" value="Japan">
</div>
<div class="option">
<label for="Egypt">Egypt</label>
<input type="radio" name="country" value="Egypt">
</div>
<div class="option">
<label for="Argentina">Argentina</label>
<input type="radio" name="country" value="Argentina">
</div>
<div class="option">
<label for="Other">Other...</label>
<input type="radio" name="country" value="Other...">
</div>
</div>
<div class="selected">
Select Country To Continue:
</div>
</div>
</div>
</div>
<div class="guest-action-container">
<div class="go-back-container">
<div class="go-back-btn">
<span class="go-back">
<span class="go-back-icon"></span>
<span class="go-back-text">BACK</span>
</span>
</div>
</div>
<div class="continue-to-site-container">
<div class="continue-to-site-btn">
<button type="submit" class="continue-to-site">
<span class="continue-text">CONTINUE</span>
<span class="continue-icon"></span>
</button>
</div>
</div>
<div class="clearFix"></div>
</div>
</div>
</form>
Here is the JS that creates the dropdown effect:
// country select drop down
$(document).ready(function(){
// country select options
const selected = document.querySelector(".selected");
const optionsContainer = document.querySelector(".options-container");
const optionsList = document.querySelectorAll(".option");
selected.addEventListener("click", () => {
optionsContainer.classList.toggle("active");
});
optionsList.forEach( o => {
o.addEventListener("click", () => {
selected.innerHTML = o.querySelector("label").innerHTML;
optionsContainer.classList.remove("active");
});
});
});
start by changing the code of the form from:
<form action="{{ route('CS') }}" method="POST">
<input value="country">
<button type="submit"> CONTINUE </button>
</form
to
<form action="{{ route('CS') }}" method="POST">
#csrf
<input value="country" name="country">
<button type="submit"> CONTINUE </button>
</form>
i hope that you are seeing the difference. while using a form in laravel you must and the csrf tokem if not i will not work.
After that in your controller just write:
public function handleSubmission(Request $request)
{
$country = $request->input('country');
}
In order to pass the value of an input to your controller you should start by having a "name" parameter in your input, then a POST route, in your web.php file, that calls the method in the controller that should get the values. Finally use request('name-of-input') and that should return the value.
Example:
view:
<form action="/user" class="admin-form" method="POST">
#csrf
<label for="form-name">Name: </label>
<input type="text" id="form-name" name="name" required>
<label for="form-email">Email: </label>
<input type="email" id="form-email" name="email" required>
<input id="form-submit" type="submit" value="Sign up!">
</form>
web.php:
Route::post('/user', 'App\Http\Controllers\UserController#store');
controller:
public function store(Request $request)
{
$user = new User();
$user->name = request('name');
$user->email = request('email');
$user->save();
return redirect('/user/create');
}
You need to include the name attribute in the input field like this:
<form action="{{ route('CS') }}" method="POST">
<input name="country" value="country">
<button type="submit"> CONTINUE </button>
</form
Then in the controller action you can reference the name field like this:
public function handleSubmission(Request $request)
{
$country = $request->input('country');
}
Related
I am trying to post a nested radio button with different field name and I have tried all I can, but I have not been successfull.
<form id="w0" class="form-vertical" action="" method="post">
<input type="hidden" name="_csrf" value="">
<label>Choose If you are human</label>
<div class="radio">
<label>
<input type="radio" name="name1" value="1">
<h4> Gender:
<input type="radio" name="male" value="m">Male
<input type="radio" name="gender" value="f">Female
</h4>
</label>
</div>
<hr>
</div>
<div class="help-block"></div>
</div><br>
<div class="form-group">
<button type="submit" class="btn btn success">Submit</button>
</div>
</form>
<?php
if(isset($_POST['name1']) && isset($_POST['gender'])){
$model->name = $_POST['name1'];
$model->gender= $_POST['gender'];
$model->save();
}
i am trying to get connected to database .html page doesnt get connected to addtodatabase.php which has many feilds like radio button,checkbox,textarea, input field .Once given submit it doesn't display the data .
<form action="addtodatabase.php" method="post">
<div class="container">
<form class="form-inline">
<fieldset>
<legend>Security Department User Registration</legend>
<div class="form-group">
<label for="Firstname">First Name</label>
<input type="text" class="form-control" id="Firstname" name="Firstname" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Secondname">Second Name</label>
<input type="text" class="form-control" id="Secondname" name="Secondname" placeholder="Text input"><br/>
</div>
</form>
.....
...
<button type="submit" class="btn btn-default">Submit</button>
addtodatabase.php page as phpmyadmin username as root , pasword NULL
<?php
$connection = mysql_connect ('root','','');
mysql_select_db('form_db');
$Firstname = $_POST ['Firstname'];
$Secondname = $_POST ['Secondname'];
echo $_POST['Firstname'];
echo '<br />';
echo $_POST['Secondname'];
$query =
"INSERT INTO form_details
(Firstname,Secondname)
values
('$Firstname','$Secondname')";
$result = mysql_query($query);
Echo "Database Saved";
mysql_close($connection);
?>
i have change the code from mysql to mysqli
<?php
$connect=mysqli_connect('localhost','root','','form_db');
if(mysqli_connect_errno($connect))
{
echo 'Failed to connect';
}
$Firstname = $_POST ['Firstname'];
$Secondname =$_POST ['Secondname'];
echo $_POST['Firstname'];
echo '<br />';
echo $_POST['Secondname'];
$query =
"INSERT INTO form_details
(Firstname,Secondname)
values
('$Firstname','$Secondname')";
$result = mysqli_query($query);
if(mysqli_affected_rows($connect) > 0){
echo "<p>Employee Added</p>";
echo "Go Back";
} else {
echo "Employee NOT Added<br />";
echo mysqli_error ($connect);
}
?>
Even after changing to mysqli it not working .addtodatabase.php
I am getting this error Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\Form\addtodatabase.php on line 2
My entire form looks this way
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="customstyle.css">
</head>
<body>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<form action="addtodatabase.php" method="post">
<div class="container">
<h1> Group of Companies</h1>
<h3> ICT & Security Department User Registration form </h3>
<h4> To be filled by HR department for New Employee </h4>
<form class="form-inline">
<fieldset>
<legend>Security Department User Registration</legend>
<div class="form-group">
<label for="Firstname">First Name</label>
<input type="text" class="form-control" id="Firstname" name="Firstname" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Secondname">Second Name</label>
<input type="text" class="form-control" id="Secondname" name="Secondname" placeholder="Text input"><br/>
</div>
</form>
<form >
<div class="form-group">
<label for="location">Dpt./Location</label>
<input type="text" class="form-control" name="location" id="location" placeholder="Text input">
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="Designation">Designation</label>
<input type="text" class="form-control" id="Designation" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Fileno">File No</label>
<input type="text" class="form-control" id="Fileno" placeholder="Password"><br/>
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="Dateofapplication">Date of Application</label>
<input type="text" class="form-control" id="Dateofapplication" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Dateofjoining">Date of Joining</label>
<input type="text" class="form-control" id="Dateofjoining" placeholder="Password"><br/>
</div>
</form>
<form>
<fieldset>
<legend>For Head office staffs only </legend>
<label>Card Type:</label>
<div id="idcard">
<label class="checkbox-inline">
<input type="checkbox" value="">Trainee ID Card
</label>
<label class="radio-inline">
<input type="radio" name="green">Green
</label>
<label class="radio-inline">
<input type="radio" name="red">Red
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Permanent ID Card
</label>
</div>
<div class="aligncheckbox">
<label>Door Access:</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Main
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Finance Division
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Meeting Room
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Goods Receiving
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Graphics & Media
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">IT Dept
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Server Room
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Dist.&Quality Control
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Warehouse Supervisor
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Pur.Office Meeting Room
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Purchase Office
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Exit
</label>
</div>
<!-- <div class="upload">
<label for="Passportcopy">Passport Copy</label>
<input type="file" id="Passportcopy">
<label for="Photo">Photo</label>
<input type="file" id="Photo">
</div>
<div>
<label class="checkbox-inline">
<input type="checkbox" value="">Finger Registration
</label>
</div> -->
<div class="container">
<div id="upload row">
<form class="form-inline">
<div class="form-group col-xs-*">
<label for="Passportcopy">Passport Copy</label>
<input type="file" class="form-control" id="Passportcopy">
</div>
<div class="form-group col-xs-*">
<label for="Photo">Photo</label>
<input type="file" class="form-control" id="Photo">
</div>
</form>
</div>
</div>
</form>
<!-- second form IT department -->
<div class="secform">
<form>
<fieldset>
<legend>IT Department User Registration </legend>
<div class="container">
<form class="form-inline">
<div class="checkbox-inline" id="erp">
<label><input type="checkbox" value="">Enroll as sales Person ERP</label>
</div>
<div class="form-group" id="textbox">
<label for="erpmodules">ERP Modules</label>
<textarea class="form-control" rows="5" id="erpmodules"></textarea>
</div>
</fieldset>
</form>
<form>
<fieldset>
<legend>For Head office staffs only </legend>
<div class="fkhaccess">
<div class="form-group" id="textbox">
<label for="fkhaccess">FKH Folder Access</label>
<textarea class="form-control" rows="5" id="fkhaccess"></textarea>
</div>
<div class="container-fluid">
<ul id="access">
<li> <label>Internet Access</label></li>
<li>
<label class="radio-inline">
<input type="radio" name="yes">Yes
</label></li>
<li>
<label class="radio-inline">
<input type="radio" name="no">No
</label></li>
</ul>
<ul id="purpose">
<li><p>If yes, Purpose </p></li>
<li>
<div class="form-group" id="textbox">
<label for="purpose">Job Purpose</label>
<textarea class="form-control" rows="5" id="purpose"></textarea>
</div></li>
</ul>
<ul id="compmail">
<li>
<div class="form-group" id="textbox" >
<label for="companyemail">Company Email</label>
<textarea class="form-control" rows="5" id="companyemail"></textarea>
</div></li>
</ul>
<form class="form-inline">
<label> Computer facilities: </label>
<label> CD ROM </label>
<label class="checkbox-inline">
<input type="checkbox" value="">Read
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Write
</label>
<label> USB PORTS </label>
<label class="checkbox-inline">
<input type="checkbox" value="">Read
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Write
</label>
</form>
<form class="form-inline">
<label class="checkbox-inline" id="label1">
<input type="checkbox" value="">Parallel Port
</label>
</form>
<form class="form-inline">
<label> Printers </label>
<label class="checkbox-inline">
<input type="checkbox" value="">MP2352(Front Office)
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">MP2501(Purchase)
</label>
</form>
<form class="form-inline">
<label class="checkbox-inline">
<input type="checkbox" value="">MP1600(MD Office)
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">DSM616(Finance)
</label>
</form>
<form class="form-inline">
<ul><li>
<label> Computer Utilities :</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Scanner
</label></li>
<li>
<label class="checkbox-inline">
<input type="checkbox" value="">Barcode Scanner
</label></li>
<li>
<label class="checkbox-inline">
<input type="checkbox" value="">Others
</label></li>
<ul id="software">
<li>
<div class="form-group" id="textbox" >
<label for="softwarerequired">Software Required </label>
<textarea class="form-control" rows="5" id="software"></textarea>
</div></li>
</ul>
</form>
</div>
</div>
</fieldset>
</form>
<div >
<div class="fill">
<div class='sign-container'>
<div class="div1">Form Filled by</div>
<div class='sign'> </div>
<div class="div2"> </div>
<div class="div3">(HR)</div>
</div>
</div>
<div class="sign-box">
<p id="signbox"> Signature </p>
<div class="div4"> </div>
<div class="fill">
<div class='sign-container'>
<div class="div1">Form Filled by</div>
<div class='sign'> </div>
<div class="div2"> </div>
<div class="div3">(Admin Manager)</div>
</div>
</div>
<div class="sign-box">
<p id="signbox"> Signature </p>
<div class="div4"> </div>
</div>
<div class="fill">
<div class='sign-container'>
<div class="div1">Form Filled by</div>
<div class='sign'> </div>
<div class="div2"> </div>
<div class="div3">(IT Manager)</div>
</div>
</div>
<div class="sign-box">
<p id="signbox"> Signature </p>
<div class="div4"> </div>
</div>
</div>
<div class="Threeform">
<form>
<fieldset>
<legend> User Confirmation </legend>
<div class="sign-container">
<div class="div1">User Name</div>
<div class='sign'> </div>
<div class="div1">System No</div>
<div class='sign'> </div>
</div>
<div class="policy-container">
<div class="div1">Received all the above mentioned facilities and understood international & FGC Cyber policy by
<div class='sign1'> </div></div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</form>
</div>
</body>
</html>
plz help me to rectify.
I am not able to connect from form.html page to addtodatabase.php .
Notice: Undefined index: firstname in C:\wamp64\www\Form\addtodatabase.php on line 12
You need to pass 2 parameters! $result = mysqli_query($connect, $query);
I have this code but I can't get what's wrong with it. Any help will be appreciated. Please don't be too quick to mark it as a duplicate without giving me a solution as I have been through all question that are similar and they do not answer my problem as I have already checked if file is uploaded be for processing it and still get this error UNDEFINED INDEX:
Html code:
<!DOCTYPE html>
<html>
<body>
<form role="form" method="post" action="test2.php">
<div class="form-group">
<div class="row">
<div class="col-xs-8">
<label class="control-label">Call Sign</label>
<input type="text" class="form-control" name="call_sign" />
</div>
<div class="col-md-4">
<label class="control-label">Picture</label>
<img src="Koala.jpg" alt="with responsive image feature" class="img-responsive img-circle">
</div>
</div>
<div class="row">
<div class="col-xs-8">
<label class="control-label">Driver First Name</label>
<input type="text" class="form-control" name="first_Name" />
</div>
</div>
<div class="row">
<div class="col-xs-8">
<label class="control-label">Driver Last Name</label>
<input type="text" class="form-control" name="last_Name" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-8">
<label for = "fileToUpload">File input</label>
<input type="file" name="fileToUpload" id="fileToUpload" >
</div>
</div>
<div class="row">
<div class="col-xs-8">
<label class="control-label">Location</label>
<input type="text" class="form-control" name="Location" />
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-4 selectContainer">
<label class="control-label">Company Shirt</label>
<select class="form-control" name="CShirt">
<option value="">Choose </option>
<option value="Good">Good</option>
<option value="Poor">Poor</option>
<option value="UniformNotWorn">Uniform Not Worn</option>
<option value="Untidy">Untidy</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-4 selectContainer">
<label class="control-label">Trousers</label>
<select class="form-control" name="Trousers">
<option value="">Choose </option>
<option value="Clean/Smart">Clean/Smart</option>
<option value="Acceptable">Acceptable</option>
<option value="Jeans/Casual">Jeans/ Casual</option>
<option value="Untidy">Untidy</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-4 selectContainer">
<label class="control-label">General Appearance</label>
<select class="form-control" name="Appearance">
<option value="">Choose </option>
<option value="Good">Good</option>
<option value="Fair">Fair</option>
<option value="Poor">Poor</option>
</select>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="control-label">In the Vehicle</label>
<div class = "checkbox">
<label><input type = "checkbox" value="Tea/Coffe" name="In_the_Vehicle"> Tea/Coffe</label>
</div>
<div class = "checkbox">
<label><input type = "checkbox" value="Eating" name="In_the_Vehicle"> Eating</label>
</div>
<div class = "checkbox">
<label><input type = "checkbox" value="Smoking" name="In_the_Vehicle"> Smoking</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label">Assessor Comments</label>
<div>
<textarea class="controlline" name="Assessor_Comments" rows="8"></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label">Driver Comments</label>
<div>
<textarea class="controlline" name="Driver_Comments" rows="8"></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label">Kit Required</label>
<div>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="DMN Shirts" /> DMN Shirts
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="DMN Jacket" /> DMN Jacket
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="BMW Jacket" /> BMW Jacket
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="Hi-Viz-Jacket" />Hi-Viz-Jacket
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="ID Badge" /> ID Badge
</label>
</div>
</div>
<div class="form-group">
<div>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="Tyre_Guage" /> Tyre Guage
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="Trade_Plate_Bands" /> Trade Plate Bands
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="MiVIS_Ruler/Kit" /> MiVIS Ruler/Kit
</label>
</div>
</div>
<div class="form-group">
<label class="control-label">Training Wanted</label>
<div>
<label class="radio-inline">
<input type="radio" name="Training_Wanted" value="Yes" /> Yes
</label>
<label class="radio-inline">
<input type="radio" name="Training_Wanted" value="No" /> No
</label>
</div>
</div>
<button type="submit" class="button" name="submit">Submit</button>
</form>
</body>
</html>
php code:
if (isset($_POST['submit'])) {
$query = "INSERT INTO spot_checkdetails(location,CShirt,trouser,appearance,kitReq,Training,fk1_callSIgn)
VALUES('$_POST[Location]','$_POST[CShirt]' ,'$_POST[Trousers]' ,'$_POST[Appearance]','$_POST[Kit_Required]' ,'$_POST[Training_Wanted]','$_POST[call_sign]')";
$result = mysqli_query($connection, $query);
if (!$result) die("database acess failed".$connection->error);
$foreignk = "select id from spot_checkdetails order by id desc limit 1";
$result = mysqli_query($connection, $foreignk);
while ($row = $result->fetch_assoc()) {
$reqry = $row["id"];
}
$query = "INSERT INTO spotcheckcomment(assCom,driCom,spot_checkdetails_id)VALUES('$_POST[Assessor_Comments]','$_POST[Driver_Comments]','".$reqry."')";
$result = mysqli_query($connection, $query);
$foreign2 = "select id from spotcheckcomment order by id desc limit 1";
$result = mysqli_query($connection, $foreign2);
while ($row = $result->fetch_assoc()) {
$reqry2 = $row["id"];
}
$foreign3 = "select fk1_callSIgn from spot_checkdetails order by id desc limit 1";
$result = mysqli_query($connection, $foreign3);
while ($row = $result->fetch_assoc()) {
$reqry3 = $row["fk1_callSIgn"];
}
if (!empty($_POST)) { // **check weather the form is submitted or not**
// Where the file is going to be placed
$target_path = "uploads/";
$random_digit = rand(0000, 9999)."_";
$jobnumber = $reqry3."_".$random_digit;
//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables
$new_file_name = $jobnumber.basename($_FILES["fileToUpload"]["name"]);
//$target_file = $target_dir .$new_file_name;
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path.$new_file_name; // basename( $_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_path)) {
echo "The file ".basename($_FILES['fileToUpload']['name']).
" has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
}
$query = "INSERT INTO spotcheckimagepath(imgname,imagepath,spot_check_comment_id)VALUES('".$new_file_name."','".$target_path."','".$reqry2."')";
$result = mysqli_query($connection, $query);
}
?>
the ERROR:) Notice: Undefined index: fileToUpload in
As w3schools.com says you need to add enctype="multipart/form-data" to you form.
multipart/form-data
No characters are encoded. This value is required when you are using forms that have a file upload control
So change this line
<form role="form" method="post" action="test2.php">
to this one
<form role="form" method="post" action="test2.php" enctype="multipart/form-data">
Also you can see here how check if image was uploaded
Change the following:
<form role="form" method="post" action="test2.php">
to
<form role="form" method="post" action="test2.php" enctype="multipart/form-data">
Would also check if var exists before trying to access it, can use
if(isset($_FILES['fileToUpload']){do something}else{error!}
Additionally suggest you move your PHP code before the html.
I have several form having the same fields: A checkbox (bootstrap switch) and a select
I want that when I pick the checkbox, the select switch to enable / disable
Thing is when I do it, only the first form is working :(
Here is my HTML
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam7" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam7" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize"><option value="0">2</option><option value="1">3</option><option value="2" selected="selected">4</option><option value="3">5</option><option value="4">6</option><option value="5">7</option><option value="6">8</option><option value="7">9</option><option value="8">10</option><option value="9">11</option><option value="10">12</option><option value="11">13</option><option value="12">14</option><option value="13">15</option></select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save7"><i></i>Guardar
</button>
</div>
</form>
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam8" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam8" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize"><option value="0">2</option><option value="1">3</option><option value="2" selected="selected">4</option><option value="3">5</option><option value="4">6</option><option value="5">7</option><option value="6">8</option><option value="7">9</option><option value="8">10</option><option value="9">11</option><option value="10">12</option><option value="11">13</option><option value="12">14</option><option value="13">15</option></select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save8"><i></i>Guardar
</button>
</div>
</form>
Here is my Jquery
$('input[name="isTeam"]').on('switchChange.bootstrapSwitch', function (event, state) {
var isChecked = $(this).is(':checked');
$('.teamSize').prop('disabled', !isChecked);
});
How can I do so that it work for all the forms in my page???
Check this snippet.
$(function() {
$('input[name="isTeam"]').on('switchChange.bootstrapSwitch', function(event, state) {
var isChecked = $(this).is(':checked');
$(this).closest('form').find('[name="teamSize"]').prop('disabled', !isChecked);
});
$("input[type=\"checkbox\"], input[type=\"radio\"]").not("[data-switch-no-init]").bootstrapSwitch();
});
<link href="http://www.bootstrap-switch.org/dist/css/bootstrap3/bootstrap-switch.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.bootstrap-switch.org/dist/js/bootstrap-switch.js"></script>
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam7" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam7" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize">
<option value="0">2</option>
<option value="1">3</option>
<option value="2" selected="selected">4</option>
<option value="3">5</option>
<option value="4">6</option>
<option value="5">7</option>
<option value="6">8</option>
<option value="7">9</option>
<option value="8">10</option>
<option value="9">11</option>
<option value="10">12</option>
<option value="11">13</option>
<option value="12">14</option>
<option value="13">15</option>
</select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save7"><i></i>Guardar
</button>
</div>
</form>
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam8" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam8" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize">
<option value="0">2</option>
<option value="1">3</option>
<option value="2" selected="selected">4</option>
<option value="3">5</option>
<option value="4">6</option>
<option value="5">7</option>
<option value="6">8</option>
<option value="7">9</option>
<option value="8">10</option>
<option value="9">11</option>
<option value="10">12</option>
<option value="11">13</option>
<option value="12">14</option>
<option value="13">15</option>
</select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save8"><i></i>Guardar
</button>
</div>
</form>
Your input element with id="teamSize" doesn't have a class called teamSize, thus your jQuery (which is looking for a class, not an id) has nothing to target.
I have the following form code but I cannot choose between these for choices.
I can't figure where is the problem. all i know about radio buttons is that they need to have the same name
<div class="controls">
<input type="radio" name="pub_place" id="1" value="1" >1
<input type="radio" name="pub_place" id="2" value="2" >2
<input type="radio" name="pub_place" id="3" value="3" >3
<input type="radio" name="pub_place" id="4" value="3" >4
</div>
this is all the view
<form class="form-horizontal" action="{{ url('/save-publicity')}}" method="post" enctype="multipart/form-data">
{{ csrf_field() }}
<fieldset>
<div class="control-group">
<label class="control-label" for="date01">Publicity Name</label>
<div class="controls">
<input type="text" class="input-xlarge" name="pub_name" required="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="date01">website Link</label>
<div class="controls">
<input type="text" class="input-xlarge" name="pub_link" required="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="fileInput">Publicity Image</label>
<div class="controls">
<input class="input-file uniform_on" name="pub_image" id="pub_image" type="file" required="">
</div>
</div>
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2">Publication status </label>
<div class="controls">
<input type="checkbox" name="pub_status" value="1">
</div>
</div>
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2">Pub Place </label>
<div class="controls">
<input type="radio" name="pub_place" id="1" value="1" >1
<input type="radio" name="pub_place" id="2" value="2" >2
<input type="radio" name="pub_place" id="3" value="3" >3
<input type="radio" name="pub_place" id="4" value="4" >4
</div>
<p>NB: <strong>Place 1 dimension:</strong> 1170x150 |
<strong>Place 2 dimension:</strong> 850x100 |
<strong>Place 3 and 4 dimension:</strong> 270x329</p>
<img style="width:300px"src="backend/brunch.jpg" alt="" />
<div class="form-actions">
<button type="submit" class="btn btn-primary">Add Publicity</button>
<button type="reset" class="btn">Cancel</button>
</div>
</div>
</fieldset>
</form>
they keep giving me NULL on the column pub_place on my database