How to insert multiple select input with same name - php

Is there any way to insert multiple value with same input name? My problem is that I am receiving multiple values.
<div class="giftcard box">
<select name="price" id="colorselector2" style="width:150px;">
<option value="">Select Gift Card Price</option>
#foreach($productDetails->giftattributes as $price)
<option value="{{$price->price}}">$ {{$price->price}}</option>
#endforeach
</select>
</div>
<div class="giftcertificate box">
<select name="price" id="colorselector" style="width:150px;">
<option value="">Select Gift Certificate Price</option>
#foreach($productDetails->giftattributes as $price)
<option value="{{$price->price}}">$ {{$price->price}}</option>
#endforeach
</select>
</div>
<div class="productasgift box">
<select name="price" id="colorselector1" style="width:150px;">
<option value="">Select Product As Gift Certificate</option>
#foreach($allproduct as $allprice)
<option value="{{$allprice->price}}">$ {{$allprice->price}}</option>
#endforeach
</select>
</div>

Try by adding [] at the end of the name, in the request then all the select/input with the same name should be in an array

Related

multiple input have same name

Here i have two fields such as follows
<div class="left_2 two">
<select name="abc_type" id="abc_type_2" class="form-control">
<option value="AB">LSK-AB</option>
<option value="AC">LSK-AC</option>
<option value="BC">LSK-BC</option>
</select>
</div>
<div class="left_2 one">
<select name="abc_type" id="abc_type_1" class="form-control">
<option value="A">LSK-A</option>
<option value="B">LSK-B</option>
<option value="C">LSK-C</option>
</select>
</div>
i will be using only one field at a time and the remaining field will be hidden and the problem am always getting the value A which is present in second select tag while getting submitted.how can i pass the correct value which i choosed
Here is the solution what ever field will be hidden add disabled in the input field Check the code below.
<?php
if(isset($_POST['abc_type'])){
echo $_POST['abc_type'];
}
?>
<form action="" method="post">
<div class="left_2 two">
<select name="abc_type" id="abc_type_2" class="form-control">
<option value="AB">LSK-AB</option>
<option value="AC">LSK-AC</option>
<option value="BC">LSK-BC</option>
</select>
</div>
<div class="left_2 one">
<select name="abc_type" id="abc_type_1" class="form-control">
<option value="A">LSK-A</option>
<option value="B">LSK-B</option>
<option value="C">LSK-C</option>
</select>
</div>
<input type="submit" name="submit" value="submit"/>
</form>

Remove the empty object value at the bottom of your select (that gets triggered by ng-repeat)

My code:
<div class="form-group">
<label>Productgroup</label>
<select id="product_group_id" name="product_group_id" class="form-control" ng-model="productGroup" ng-change="changedType(val)">
<option style="display: none" value="">Choose a productgroup</option>
#foreach ($product_groups as $product_group)
<option value="{{$product_group->id}}">{{$product_group->name}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label>Product</label>
<select id="product_id" name="product_id" class="form-control" ng-model="form.product_id">
<option style="display: none" value="">Choose a product</option>
<option value="#{{product.id}}" ng-repeat="product in products">#{{product.name}}<option>
</select>
</div>
The product group select basically filters the next select; products.
I keep getting this empty option value included at the bottom of my product select options, like so:
<option value=""></option>
I've already used <option style="display: none" value="">Choose product</option> to remove the first empty option value in my product select.
Update:
Use ng-options instead of ng-repeat, like so:
<div class="form-group">
<label>Product</label>
<select id="product_id" name="product_id" class="form-control" ng-options="product.id as product.name for product in products" ng-model="form.product_id">
<option style="display: none" value="">Choose a product</option>
</select>
</div>
i would say your ng-repeat is in the wrong place, probably should use the standard angular way (https://docs.angularjs.org/api/ng/directive/select):
<select name="mySelect" id="mySelect" ng-options="option.name for option in data.availableOptions track by option.id" ng-model="data.selectedOption"></select>
then if you want to remove the empty/first element, have a look at this Angular JS Remove Blank option from Select Option
You should check if the data isn't empty, for example:
<select id="product_group_id" name="product_group_id" class="form-control" ng-model="productGroup" ng-change="changedType(val)">
<option style="display: none" value="">Choose a productgroup</option>
foreach ($product_groups as $product_group)
if (!empty($product_group->name) && !empty($product_group->id)) {
<option value="{{$product_group->id}}">{{$product_group->name}}</option>
}
endforeach
</select>
But I think you should try to find where this empty line come from to avoid further problems

Auto populate next select box based on previous field answer

I have 2 questions if the answer to the first question is 1> I want the next answer to be auto populated as Yes. Can someone steer me in the right direction please?
<div class="field">
<!-- Number of Employees -->
<label>Number of Employees</label>
<div class="styled-select">
<select name="NoOfEmployees" class="validate[required]" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<?php
foreach (range(0, 49) as $number) {
echo '<option value="'.$number.'">'.$number.'</option>';
}
?>
<option value="50 Plus">50+</option>
</select>
</div>
</div>
<div class="field">
<!-- Employers Liability Cover Required -->
<label>Employers Liability Cover Required</label>
<div class="styled-select">
<select name="EmployersLiabilityCover" class="validate[required]" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
</div>
If the answer is 0 then I just need the next question to stay as Please Select.
use jquery onchange , give selectbox inputs seperate id,
Use jquery val() to get selectbox value
use if condition to check its greater than 0
code shown below
<div class="field">
<!-- Number of Employees -->
<label>Number of Employees</label>
<div class="styled-select">
<select name="NoOfEmployees" class="validate[required]" id="select1" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<?php
foreach (range(0, 49) as $number) {
echo '<option value="'.$number.'">'.$number.'</option>';
}
?>
<option value="50 Plus">50+</option>
</select>
</div>
</div>
<div class="field">
<!-- Employers Liability Cover Required -->
<label>Employers Liability Cover Required</label>
<div class="styled-select">
<select name="EmployersLiabilityCover" id="select2" class="validate[required]" data-prompt-position="topLeft:110,15">
<option value="">Please select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script>
$('#select1').on('change', function() {
if(this.value>0)
{
$("#select2").val("Yes");
}
else
{
$("#select2").val("");
}
});
</script>

select value not taking properly

i have one big form.. there have some so many select option. and its from to mail function. bellow is my code
<label>Type of Event? </label>
<select id="eventtype" title="" name="eventtype" class="required select">
<option value="">Select Your Event Type</option>
<option value="WEDDINGS">WEDDINGS</option>
<option value="CORPORATE">CORPORATE EVENT</option>
<option value="SPECIAL">SPECIAL EVENT</option>
<option value="OTHER">OTHER SINGLE SERVICES</option>
</select>
<div class="cls"></div>
<div class="container">
<div class="WEDDINGS">
<label>Package</label>
<select name="Package" id="Package">
<option value="Day Of Coordination">Day Of Coordination</option>
<option value="Week of Coordination">Week of Coordination</option>
<option value="Month of Coordination">Month of Coordination</option>
</select>
</div>
<div class="CORPORATE">
<label>Package</label>
<select name="Package" id="Package">
<option value="Meetings">Meetings</option>
<option value="Client Appreciation">Client Appreciation</option>
<option value="Conference & Conventions">Conference & Conventions</option>
<option value="Corporate Shows">Corporate Shows</option>
<option value="Employee Appreciation">Employee Appreciation</option>
</select>
</div>
<div class="SPECIAL">
<label>Package</label>
<select name="Package" id="Package">
<option value="Engagements">Engagements</option>
<option value="Bar Mitzvah">Bar Mitzvah</option>
<option value="Quincearas">Quincearas</option>
<option value="Birthdays">Birthdays</option>
<option value="Fashion Shows">Fashion Shows</option>
<option value="Showers">Showers</option>
</select>
</div>
<div class="OTHER">
<label>Package</label>
<select name="Package" id="Package">
<option value="Wedding Consultation and Guidance Only">Wedding Consultation and Guidance Only</option>
<option value="Venue Search Only">Venue Search Only</option>
<option value="Coordination of Engagement Party Only">Coordination of Engagement Party Only</option>
<option value="Providing Qualified and Screened Vendors Only">Providing Qualified and Screened Vendors Only</option>
</select>
js code for realtion with drop down
<script>
$(document).ready(function() {
$('#eventtype').bind('change', function() {
var elements = $('div.container').children().hide();
var value = $(this).val();
if (value.length) {
elements.filter('.' + value).show();
}
}).trigger('change');
});
</script>
my from is like if select WEDDING then show Wedding div so show there another drop down.. and if select CORPORATE EVENT then show CORPORATE EVENT div... but no matter what drop down i select when mail go correct data not pass. its goes always OTHER div 1st select value mean "Wedding Consultation and Guidance Only" ... i have no idea why... may be i mistake something... bellow is part of php mail code
if($violation)
{
$eventtype = $_POST['eventtype'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$datepicker = $_POST['datepicker'];
$datepicker2 = $_POST['datepicker2'];
$time = $_POST['time'];
$EMAIL = $_POST['EMAIL'];
$phone = $_POST['phone'];
$Package = $_POST['Package'];
$otherfound = $_POST['otherfound'];
if (isset($_POST['found_group'])) {
$found = $_POST['found_group'];
for ($i=0; $i<count($found); $i++) {
//echo $found[$i]."<br />";
$found=implode("<br />",$found);
}
}
all i want to correct data will go .. can you tell me where i am mistaking... thanks
you may need to do something like this
<label>Type of Event? </label>
<select id="eventtype" title="" name="eventtype" name="eventtype" class="required select">
<option value="">Select Your Event Type</option>
<option value="WEDDINGS">WEDDINGS</option>
<option value="CORPORATE">CORPORATE EVENT</option>
<option value="SPECIAL">SPECIAL EVENT</option>
<option value="OTHER">OTHER SINGLE SERVICES</option>
</select>
<div class="cls"></div>
<div class="container">
<div class="WEDDINGS">
<label>Package</label>
<select name="WEDDINGSPackage" id="WEDDINGSPackage">
<option value="Day Of Coordination">Day Of Coordination</option>
<option value="Week of Coordination">Week of Coordination</option>
<option value="Month of Coordination">Month of Coordination</option>
</select>
</div>
<div class="CORPORATE">
<label>Package</label>
<select name="CORPORATEPackage" id="CORPORATEPackage">
<option value="Meetings">Meetings</option>
<option value="Client Appreciation">Client Appreciation</option>
<option value="Conference & Conventions">Conference & Conventions</option>
<option value="Corporate Shows">Corporate Shows</option>
<option value="Employee Appreciation">Employee Appreciation</option>
</select>
</div>
.......
and at PHP end you have to do something like this
if (isset($_POST['eventtype'])) {
$subOptSelect = $_POST['eventtype'] . 'Package';
if (isset($_POST[$subOptSelect])){
$sub = $_POST[$subOptSelect];
}
}
I have prefixed the value of the first select to the sub selects and it becomes easier at php end.
Edit: Here is the code you may require.
$package='';
if (!empty($eventtype)) {
if (!empty($_POST[$eventtype.'Package'])){
$package = $_POST[$eventtype.'Package'];
//$package contains the option selected in the sub option.
}else{
//nothing selected in the sub dropdown. you have to add code to handle this
}
}else{
//nothing selected in the first dropdown. you have to add code to handle this
}
And your email can be:
<table width='95%' cellpadding='0' cellspacing='11'>
<tr>
<td width='189'>Event Type :</td>
<td>$eventtype</td>
</tr>
<tr>
<td>Package :</td><td>$package</td>
</tr>
<tr>
<td>First Name :</td><td>$firstname</td>
</tr>
<tr>
You can't reuse the name attribute in html, and you're html form has the same name for each select tag. What is happening is the markup is processed sequentially so it only uses the last declaration of the name="Package" select so the selected value from that will always be passed to the server as the $_POST['package']. Do something like this instead:
<label>Type of Event? </label>
<select id="eventtype" title="" name="eventtype" class="required select">
<option value="">Select Your Event Type</option>
<option value="WEDDINGS">WEDDINGS</option>
<option value="CORPORATE">CORPORATE EVENT</option>
<option value="SPECIAL">SPECIAL EVENT</option>
<option value="OTHER">OTHER SINGLE SERVICES</option>
</select>
<div class="cls"></div>
<div class="container">
<div class="WEDDINGS">
<label>Package</label>
<select name="Weddings-Package" id="Weddings-Package">
<option value="Day Of Coordination">Day Of Coordination</option>
<option value="Week of Coordination">Week of Coordination</option>
<option value="Month of Coordination">Month of Coordination</option>
</select>
</div>
<div class="CORPORATE">
<label>Package</label>
<select name="Corporate-Package" id="Corporate-Package">
<option value="Meetings">Meetings</option>
<option value="Client Appreciation">Client Appreciation</option>
<option value="Conference & Conventions">Conference & Conventions</option>
<option value="Corporate Shows">Corporate Shows</option>
<option value="Employee Appreciation">Employee Appreciation</option>
</select>
</div>
<div class="SPECIAL">
<label>Package</label>
<select name="Special-Package" id="Special-Package">
<option value="Engagements">Engagements</option>
<option value="Bar Mitzvah">Bar Mitzvah</option>
<option value="Quincearas">Quincearas</option>
<option value="Birthdays">Birthdays</option>
<option value="Fashion Shows">Fashion Shows</option>
<option value="Showers">Showers</option>
</select>
</div>
<div class="OTHER">
<label>Package</label>
<select name="Other-Package" id="Other-Package">
<option value="Wedding Consultation and Guidance Only">Wedding Consultation and Guidance Only</option>
<option value="Venue Search Only">Venue Search Only</option>
<option value="Coordination of Engagement Party Only">Coordination of Engagement Party Only</option>
<option value="Providing Qualified and Screened Vendors Only">Providing Qualified and Screened Vendors Only</option>
</select>
when the post data is sent to the server it is sent in the $_POST variable as an associative array with the names as the key, if you make the name of each select unique then you should be able to achieve what you want. You might want to pass the name of which select was used to the server so you know which variable to grab in php. As another note the id value for every tag should be unique, as that is the purpose of an id attribute.

IF POST Variables equals then redirect

Im trying to get form post values and if they match certain criteria redirect only my page doesnt seem to...
I have a form with multiple input fields
HTML
<form method="post" action="?page_id=151">
<div style="display: block;" id="Q1">
<label for="vehicleType">1. What type of vehicles do you have?</label>
<select id="vehicleType" name="vehicleType">
<option selected="selected" value="choose">Please choose</option>
<option value="hgv">HGV</option>
<option value="psv">PSV</option>
<option value="lgv">LGV</option>
<option value="car">Car</option>
<option value="mixed">Mixed Fleet</option>
</select>
</div>
<div id="Q2group1">
<label for="coverageRegion">2. Do you require national or international coverage?</label>
<select id="coverageRegion" name="coverageRegion">
<option selected="selected" value="choose">Please choose</option>
<option value="national">National</option>
<option value="international">International</option>
</select>
</div>
<div id="Q2others">
<label for="pricing">2. Do you prefer a fixed weekly price or a pump-related price?</label>
<select id="pricing" name="pricing">
<option selected="selected" value="choose">Please choose</option>
<option value="fixed">Weekly fixed price</option>
<option value="pump">Pump-related price</option>
</select>
</div>
<div id="Q3group1">
<label for="locationType">3. What type of site do you prefer?</label>
<select id="locationType" name="locationType">
<option selected="selected" value="choose">Please choose</option>
<option value="truckstops">Truck stops at lowest price</option>
<option value="motorway">Branded motorway sites</option>
</select>
</div>
<div id="Q3others">
<label for="siteCoverage">3. What site coverage do you need?</label>
<select id="siteCoverage" name="siteCoverage">
<option value="choose">Please choose</option>
<option value="countysites">County</option>
<option value="nationalsites">National</option>
</select>
</div>
<div id="Q4others">
<label for="county">4. Select your county:</label>
<select id="county" name="county">
<option value="choose">Please choose</option>
<optgroup label="England">
<option>Bedfordshire</option>
<option>Berkshire</option>
<option>Bristol</option>
<option>Tyrone</option>
</optgroup>
</select></div>
<div id="searchbuttondiv"> <input type="submit" id="searchbutton" onclick="_gaq.push(['_trackEvent', 'Fuel Card Search', 'Homepage Select Criteria'])"> </div>
</form>
PHP
if ($_POST['vehicleType'] == 'car' && $_POST['pricing'] == 'fixed' && $_POST['coverageRegion'] == 'national') {
echo '<script>alert("hi");</script>';
// header('Location: /car-weekly-national/');
}
One of your conditions is falling (and because they are all bound by AND, all of the if statement fails.
Have an else statement where you var_dump all relevant variables and see what's wrong.
Sorry everyone, oversight by me, I was checking to see if the wrong variable had been posted, wouldn't have found it if it wasn't for the suggestions to add an else statement, thanks!

Categories