Re load dropdown menu on page load - php

I have an html form that I have been using to POST to a php form, this saves the posted data into the database. I am now loading the data back into the form when I click edit, this works fine for the text fields as I can just use
value="<?php echo $somefield ?>"
The problem is im not sure how to re select my dropdown menu. The menu looks like this and is used for selecting a category, but when the page reloads nothing happens and the dropdown isn't reloaded.
<select name="category" id="category">
<option>- Select A Category -</option>
<optgroup label="Tractors">
<option value="Tractor">Tractor</option>
<option value="Compact">Compact</option>
<option value="Forklift">Forklift</option>
<option value="Load All">Load All</option>
<option value="Loader">Loader</option>
<option value="Maniscopic">Maniscopic</option>
<option value="Masted">Masted</option>
<option value="Piviot">Piviot</option>
<option value="Telescopic">Telescopic</option>
<option value="UTV">UTV</option>
</optgroup>
<optgroup label="Machinery">
<option value="Attachments">Attachments</option>
<option value="Bale Handling">Bale Handling</option>
<option value="Cultivation Equipment">Cultivation Equipment</option>
<option value="Drills">Drills</option>
<option value="Feeders">Feeders</option>
<option value="Fertlizer Spreaders">Fertlizer Spreaders</option>
<option value="Grass Harrows">Grass Harrows</option>
<option value="Grassland Equipment">Grassland Equipment</option>
<option value="Hedge Cutters">Hedge Cutters</option>
<option value="Mowers">Mowers</option>
<option value="Muck Spreaders ">Muck Spreaders </option>
<option value="Ploughs">Ploughs</option>
<option value="Post Hammers">Post Hammers</option>
<option value="Power Harrows">Power Harrows</option>
<option value="Rakes">Rakes</option>
<option value="Rolls">Rolls</option>
<option value="Rotovators">Rotovators</option>
<option value="Shredders">Shredders</option>
<option value="Splitters">Splitters</option>
<option value="Sprayers">Sprayers</option>
<option value="Spreaders">Spreaders</option>
<option value="Tankers">Tankers</option>
<option value="Tedders">Tedders</option>
<option value="Toppers">Toppers</option>
<option value="Trailers">Trailers</option>
<option value="Wrappers">Wrappers</option>
</optgroup>
<optgroup label="Forklifts">
</optgroup>
</select>

<?php
echo '<select>';
foreach( $names as $name )
echo '<option value="'.$name.'" '.($name==$selected?' selected="selected"':'').'>'.$name.'</option>'
echo '</select>';
?>

When building the list the selected option should have the attribute selected="selected".

Related

can I $_POST multiple assoc. arrays

I am.working on a user input availability database. I order to standardize the information, I want to use more than 1 mulitiple select inputs.
<form method="post" action=''example.php">
Gamerid:<input ="text" name ="gamerid"/></br>
Monday:<select name="monday[]" multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select> </br>
Tuesday:<select name="tuesday[]"multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select> </br>
Wednesday:<select name="wednesday[]" multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select> </br>
etc for every day of the week.. so far, I believe my code is correct but POST seems to not appreciate it. Is it even possible..?
The end goal it to serialise the $_POST arrays, into strings, then store them in sql db.
Any help here would be appreciated.
In action page you will get array then by using implode you can convert to string then you can insert in to database.
try for this code.
<form method="post">
Tuesday:<select name="tuesday[]"multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select>
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
$var=$_POST['tuesday'];
echo implode(",",$var);
}
?>

Display fields name or value and label in drop-down list using prestashop

I am new in prestashop. I want to display all field's labels and its name or value in a drop-down. These fields will be add product form fields. My example is given below.
<select name="select[]" class="form-control advance_select">
<option value="">- None -</option>
<optgroup label="Product Information">
<option value="4">Product ID</option>
<option value="15">EAN13 or JAN barcode</option>
<option value="16">UPC barcode</option>
<option selected="" value="1">Product Name</option>
<option value="2">Reference code</option>
<option value="status">Status (Y/N)</option>
<option value="language">ISO Language</option>
<option value="iso_code">Currency ISO Code</option>
<option value="main_category">Name of default Category </option>
<option value="category_associated">Name of Associated categories </option>
<option value="17">Product Main Image</option>
<option value="18">Product Addition Image</option>
<option value="7">Pre-tax wholesale price</option>
<option value="8">Pre-tax retail price</option>
<option value="3">Product Tags</option>
<option value="5">Product Full Description</option>
<option value="6">Product Short Description</option>
<option value="9">Meta title</option>
<option value="10">Meta description</option>
<option value="11">Meta keywords</option>
<option value="12">Friendly URL</option>
<option value="14">Quantities</option>
<option value="supplier">Supplier Name</option>
<option value="manufacturer">Manufacturer Name</option>
</optgroup>
</select>
Can I do like this in prestashop? Please help me on this.

Passing checkbox values to php - missing values

I am having an issue where we cannot join up our checkboxes with the other fields being passsed.
If we only check the second checkbox it will take the value of the first row select box.
The rows are joined up by the date e.g.2014-06-02, 2014-06-03
HTML
<input type="checkbox" name="date_choice[]" value="2014-06-02">
<select id="event_start" name="event_start[2014-06-02][]" onchange="area_choice_click()">
<option value="">Start Time</option>
<option value="01:00">1.00AM</option>
<option value="02:00">2.00AM</option>
<option value="03:00">3.00AM</option>
</select>
<select id="event_end" name="event_end[2014-06-02][]" onchange="area_choice_click()">
<option value="">End Time</option>
<option value="01:00">1.00AM</option>
<option value="02:00">2.00AM</option>
<option value="03:00">3.00AM</option>
</select>
<input type="checkbox" name="date_choice[]" value="2014-06-03">
<select id="event_start" name="event_start[2014-06-03][]" onchange="area_choice_click()">
<option value="">Start Time</option>
<option value="01:00">1.00AM</option>
<option value="02:00">2.00AM</option>
<option value="03:00">3.00AM</option>
</select>
<select id="event_end" name="event_end[2014-06-03][]" onchange="area_choice_click()">
<option value="">End Time</option>
<option value="01:00">1.00AM</option>
<option value="02:00">2.00AM</option>
<option value="03:00">3.00AM</option>
</select>
PHP
foreach($_POST['date_choice'] as $key=>$team_id){
$event_date = $_POST['date_choice'][$key];
echo"$event_date";
$event_start=$_POST['event_start'][$event_date][$key];
}

restoring multi-select selections in a list box in PHP/HTML

so I have a multi-select listbox...
<select id="extfeat" name="extfeat[]" size="6" multiple="">
<option value="Wheel_Chair Accessible">Wheel Chair Accessible</option>
<option value="Fruit_Trees">Fruit Trees</option>
<option value="Large_Trees">Large Trees</option>
<option value="Rolling">Rolling</option>
<option value="Other">Other</option>
<option value="Level">Level</option>
<option value="Wooded">Wooded</option>
<option value="Outbuildings">Outbuildings</option>
<option value="Gazebo">Gazebo</option>
<option value="Workshop Area">Workshop Area</option>
<option value="Sauna">Sauna</option>
<option value="Courtyard">Courtyard</option>
<option value="Lake_Access">Lake Access</option>
<option value="Tillable">Tillable</option>
<option value="Deck">Deck</option>
<option value="Lakeview">Lakeview</option>
<option value="Propane_Tank_-_Leased">Propane Tank - Leased</option>
<option value="Dock">Dock</option>
<option value="Landscaped">Landscaped</option>
<option value="Propane_Tank - Owned">Propane Tank - Owned</option>
<option value="Fenced_Yard">Fenced Yard</option>
<option value="Water_Frontage">Water Frontage</option>
<option value="Concrete_Parking">Concrete Parking</option>
<option value="Pond">Pond</option>
<option value="Tennis_Court">Tennis Court</option>
<option value="Circle_Drive">Circle Drive</option>
<option value="Horses_Allowed">Horses Allowed</option>
<option value="Patio_Enclosed">Patio Enclosed</option>
<option value="Sprinkler_System">Sprinkler System</option>
<option value="Brick_Trim">Brick Trim</option>
<option value="Guest_House">Guest House</option>
<option value="Terraced">Terraced</option>
<option value="Hot_Tub">Hot Tub</option>
<option value="Outdoor_Sign">Outdoor Sign</option>
<option value="Garden">Garden</option>
<option value="Above_ground_pool">Above ground pool</option>
<option value="Ground_Lvl_Access">Ground Lvl Access</option>
<option value="Handicap_Access">Handicap Access</option>
<option value="Patio">Patio</option>
<option value="Garage_Opener">Garage Opener</option>
<option value="In-ground_Pool">In-ground Pool</option>
<option value="Greenhouse">Greenhouse</option>
<option value="Pasture">Pasture</option>
<option value="Shed">Shed</option>
<option value="Boat_House">Boat House</option>
<option value="Antenna">Antenna</option>
<option value="Generator">Generator</option>
<option value="Asphalt_Parking">Asphalt Parking</option>
<option value="Sloping">Sloping</option>
<option value="Porch">Porch</option>
<option value="Satellite_Dish">Satellite Dish</option>
<option value="Screened_Porch">Screened Porch</option>
<option value="Underground_Pet_Fence">Underground Pet Fence</option>
<option value="Pool">Pool</option>
</select>
so lets say a user selects 7 options and does a search...my search has a refine option and this along with many other fields are saved and stored in a hidden div that can be brought up again by pressing a button...
the problem is that the extfeats[] variable isn't retaining the selections after the POST...i need to somehow transfer the existing multiselections as the defaults.
If you know which options were selected you can mark them as selected by default with: selected="selected":
<select id="extfeat" name="extfeat[]" size="6" multiple="">
<option value="Wheel_Chair Accessible">Wheel Chair Accessible</option>
<option value="Fruit_Trees" selected="selected">Fruit Trees</option>
// ..
</select>
On a minor note multiple="" should probably be multiple="multiple".
ok...well it turned out to be easier then i thought...
<select id="extfeat" name="extfeat[]" size="6" multiple="">
<option value="Wheel_Chair Accessible" <? if (in_array("Wheel_Chair Accessible",$extfeat)) echo "selected" ?> >Wheel Chair Accessible</option>
<option value="Fruit_Trees" <? if (in_array("Fruit_Trees",$extfeat)) echo "selected" ?>>Fruit Trees</option>
...
thxs to Frits van Campen for your gentle push in the right direction ;)

How do I post 3 values from a form into 1?

I have the following date picker with 3 different select ids
<form id="testform" method="get" action="../Untitled-1.html">
<select id="date-sel-dd" name="date-sel-dd">
<option value="-1">Day</option>
<option value="1">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">5th</option>
<option value="6">6th</option>
<option value="7">7th</option>
<option value="8">8th</option>
<option value="9">9th</option>
<option value="10">10th</option>
<option value="11">11th</option>
<option value="12">12th</option>
<option value="13">13th</option>
<option value="14">14th</option>
<option value="15">15th</option>
<option value="16">16th</option>
<option value="17">17th</option>
<option value="18">18th</option>
<option value="19">19th</option>
<option value="20">20th</option>
<option value="21">21st</option>
<option value="22">22nd</option>
<option value="23">23rd</option>
<option value="24">24th</option>
<option value="25">25th</option>
<option value="26">26th</option>
<option value="27">27th</option>
<option value="28">28th</option>
<option value="29">29th</option>
<option value="30">30th</option>
<option value="31">31st</option>
</select>
<select id="date-sel-mm" name="date-sel-mm">
<option value="-1">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="date-sel" name="date-sel">
<option value="-1">Year</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
<input type="submit" name="submit" id="submit" value="Submit" />
I need to get the values from these 3 differnt select fields and post it with the form to a new named: 'arrival'.
When I submit to the page I want my url to look like:
mydomain.php?arrival=date-sel-dd/date-sel-mm/date-sel
You could use an array.
Rename all select with arrival[].
In your php page you can get that value as an array. Try:
print_r($_POST['arrival']);
If you want to join the date use:
$date = implode('/', $_POST['arrival']);
header('Location: mydomain.php?arrival=' . $date);

Categories