Laurent Coulon Laurent Coulon - 1 month ago 6
PHP Question

How could SELECT form with OPTIONS pass multiple parameters when submitted?

I have an simple HTML form with select and options that is supposed to send Timezones details.

When the form is submitted, i would like to pass / send several values.
I found different approches examples but none exactly suits my needs.


  • At the moment, the form below is able to send only 1 parameters as value :
    Let's say first choice has been submitted, here the value send is the timezone ID : 1



ie :

http://timezone.htm/?TZ=1



Hope you could help me to find an easy way with PHP or Javascript to pass more than parameter with that GET form.



<form method="GET" action="">

<select name="TZ">
<option value="1" gmtAdjustment="GMT-12:00" useDaylightTime="0" timeshift="-12">(GMT-12:00) International Date Line West</option>
<option value="2" gmtAdjustment="GMT-11:00" useDaylightTime="0" timeshift="-11">(GMT-11:00) Midway Island, Samoa</option>
<option value="3" gmtAdjustment="GMT-10:00" useDaylightTime="0" timeshift="-10">(GMT-10:00) Hawaii</option>
<option value="4" gmtAdjustment="GMT-09:00" useDaylightTime="1" timeshift="-9">(GMT-09:00) Alaska</option>
<option value="5" gmtAdjustment="GMT-08:00" useDaylightTime="1" timeshift="-8">(GMT-08:00) Pacific Time (US & Canada)</option>
<option value="6" gmtAdjustment="GMT-08:00" useDaylightTime="1" timeshift="-8">(GMT-08:00) Tijuana, Baja California</option>
<option value="7" gmtAdjustment="GMT-07:00" useDaylightTime="0" timeshift="-7">(GMT-07:00) Arizona</option>
<option value="8" gmtAdjustment="GMT-07:00" useDaylightTime="1" timeshift="-7">(GMT-07:00) Chihuahua, La Paz, Mazatlan</option>
<option value="9" gmtAdjustment="GMT-07:00" useDaylightTime="1" timeshift="-7">(GMT-07:00) Mountain Time (US & Canada)</option>
<option value="10" gmtAdjustment="GMT-06:00" useDaylightTime="0" timeshift="-6">(GMT-06:00) Central America</option>
<option value="11" gmtAdjustment="GMT-06:00" useDaylightTime="1" timeshift="-6">(GMT-06:00) Central Time (US & Canada)</option>
<option value="12" gmtAdjustment="GMT-06:00" useDaylightTime="1" timeshift="-6">(GMT-06:00) Guadalajara, Mexico City, Monterrey</option>
<option value="13" gmtAdjustment="GMT-06:00" useDaylightTime="0" timeshift="-6">(GMT-06:00) Saskatchewan</option>
<option value="14" gmtAdjustment="GMT-05:00" useDaylightTime="0" timeshift="-5">(GMT-05:00) Bogota, Lima, Quito, Rio Branco</option>
<option value="15" gmtAdjustment="GMT-05:00" useDaylightTime="1" timeshift="-5">(GMT-05:00) Eastern Time (US & Canada)</option>
<option value="16" gmtAdjustment="GMT-05:00" useDaylightTime="1" timeshift="-5">(GMT-05:00) Indiana (East)</option>
<option value="17" gmtAdjustment="GMT-04:00" useDaylightTime="1" timeshift="-4">(GMT-04:00) Atlantic Time (Canada)</option>
<option value="18" gmtAdjustment="GMT-04:00" useDaylightTime="0" timeshift="-4">(GMT-04:00) Caracas, La Paz</option>
<option value="19" gmtAdjustment="GMT-04:00" useDaylightTime="0" timeshift="-4">(GMT-04:00) Manaus</option>
<option value="20" gmtAdjustment="GMT-04:00" useDaylightTime="1" timeshift="-4">(GMT-04:00) Santiago</option>
<option value="21" gmtAdjustment="GMT-03:30" useDaylightTime="1" timeshift="-3.5">(GMT-03:30) Newfoundland</option>
<option value="22" gmtAdjustment="GMT-03:00" useDaylightTime="1" timeshift="-3">(GMT-03:00) Brasilia</option>
<option value="23" gmtAdjustment="GMT-03:00" useDaylightTime="0" timeshift="-3">(GMT-03:00) Buenos Aires, Georgetown</option>
<option value="24" gmtAdjustment="GMT-03:00" useDaylightTime="1" timeshift="-3">(GMT-03:00) Greenland</option>
<option value="25" gmtAdjustment="GMT-03:00" useDaylightTime="1" timeshift="-3">(GMT-03:00) Montevideo</option>
<option value="26" gmtAdjustment="GMT-02:00" useDaylightTime="1" timeshift="-2">(GMT-02:00) Mid-Atlantic</option>
<option value="27" gmtAdjustment="GMT-01:00" useDaylightTime="0" timeshift="-1">(GMT-01:00) Cape Verde Is.</option>
<option value="28" gmtAdjustment="GMT-01:00" useDaylightTime="1" timeshift="-1">(GMT-01:00) Azores</option>
<option value="29" gmtAdjustment="GMT+00:00" useDaylightTime="0" timeshift="0">(GMT+00:00) Casablanca, Monrovia, Reykjavik</option>
<option value="30" gmtAdjustment="GMT+00:00" useDaylightTime="1" timeshift="0">(GMT+00:00) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London</option>
<option value="31" gmtAdjustment="GMT+01:00" useDaylightTime="1" timeshift="1">(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>
<option value="32" gmtAdjustment="GMT+01:00" useDaylightTime="1" timeshift="1">(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>
<option value="33" gmtAdjustment="GMT+01:00" useDaylightTime="1" timeshift="1">(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</option>
<option value="34" gmtAdjustment="GMT+01:00" useDaylightTime="1" timeshift="1">(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb</option>
<option value="35" gmtAdjustment="GMT+01:00" useDaylightTime="1" timeshift="1">(GMT+01:00) West Central Africa</option>
<option value="36" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Amman</option>
<option value="37" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Athens, Bucharest, Istanbul</option>
<option value="38" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Beirut</option>
<option value="39" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Cairo</option>
<option value="40" gmtAdjustment="GMT+02:00" useDaylightTime="0" timeshift="2">(GMT+02:00) Harare, Pretoria</option>
<option value="41" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius</option>
<option value="42" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Jerusalem</option>
<option value="43" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Minsk</option>
<option value="44" gmtAdjustment="GMT+02:00" useDaylightTime="1" timeshift="2">(GMT+02:00) Windhoek</option>
<option value="45" gmtAdjustment="GMT+03:00" useDaylightTime="0" timeshift="3">(GMT+03:00) Kuwait, Riyadh, Baghdad</option>
<option value="46" gmtAdjustment="GMT+03:00" useDaylightTime="1" timeshift="3">(GMT+03:00) Moscow, St. Petersburg, Volgograd</option>
<option value="47" gmtAdjustment="GMT+03:00" useDaylightTime="0" timeshift="3">(GMT+03:00) Nairobi</option>
<option value="48" gmtAdjustment="GMT+03:00" useDaylightTime="0" timeshift="3">(GMT+03:00) Tbilisi</option>
<option value="49" gmtAdjustment="GMT+03:30" useDaylightTime="1" timeshift="3.5">(GMT+03:30) Tehran</option>
<option value="50" gmtAdjustment="GMT+04:00" useDaylightTime="0" timeshift="4">(GMT+04:00) Abu Dhabi, Muscat</option>
<option value="51" gmtAdjustment="GMT+04:00" useDaylightTime="1" timeshift="4">(GMT+04:00) Baku</option>
<option value="52" gmtAdjustment="GMT+04:00" useDaylightTime="1" timeshift="4">(GMT+04:00) Yerevan</option>
<option value="53" gmtAdjustment="GMT+04:30" useDaylightTime="0" timeshift="4.5">(GMT+04:30) Kabul</option>
<option value="54" gmtAdjustment="GMT+05:00" useDaylightTime="1" timeshift="5">(GMT+05:00) Yekaterinburg</option>
<option value="55" gmtAdjustment="GMT+05:00" useDaylightTime="0" timeshift="5">(GMT+05:00) Islamabad, Karachi, Tashkent</option>
<option value="56" gmtAdjustment="GMT+05:30" useDaylightTime="0" timeshift="5.5">(GMT+05:30) Sri Jayawardenapura</option>
<option value="57" gmtAdjustment="GMT+05:30" useDaylightTime="0" timeshift="5.5">(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
<option value="58" gmtAdjustment="GMT+05:45" useDaylightTime="0" timeshift="5.75">(GMT+05:45) Kathmandu</option>
<option value="59" gmtAdjustment="GMT+06:00" useDaylightTime="1" timeshift="6">(GMT+06:00) Almaty, Novosibirsk</option>
<option value="60" gmtAdjustment="GMT+06:00" useDaylightTime="0" timeshift="6">(GMT+06:00) Astana, Dhaka</option>
<option value="61" gmtAdjustment="GMT+06:30" useDaylightTime="0" timeshift="6.5">(GMT+06:30) Yangon (Rangoon)</option>
<option value="62" gmtAdjustment="GMT+07:00" useDaylightTime="0" timeshift="7">(GMT+07:00) Bangkok, Hanoi, Jakarta</option>
<option value="63" gmtAdjustment="GMT+07:00" useDaylightTime="1" timeshift="7">(GMT+07:00) Krasnoyarsk</option>
<option value="64" gmtAdjustment="GMT+08:00" useDaylightTime="0" timeshift="8">(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
<option value="65" gmtAdjustment="GMT+08:00" useDaylightTime="0" timeshift="8">(GMT+08:00) Kuala Lumpur, Singapore</option>
<option value="66" gmtAdjustment="GMT+08:00" useDaylightTime="0" timeshift="8">(GMT+08:00) Irkutsk, Ulaan Bataar</option>
<option value="67" gmtAdjustment="GMT+08:00" useDaylightTime="0" timeshift="8">(GMT+08:00) Perth</option>
<option value="68" gmtAdjustment="GMT+08:00" useDaylightTime="0" timeshift="8">(GMT+08:00) Taipei</option>
<option value="69" gmtAdjustment="GMT+09:00" useDaylightTime="0" timeshift="9">(GMT+09:00) Osaka, Sapporo, Tokyo</option>
<option value="70" gmtAdjustment="GMT+09:00" useDaylightTime="0" timeshift="9">(GMT+09:00) Seoul</option>
<option value="71" gmtAdjustment="GMT+09:00" useDaylightTime="1" timeshift="9">(GMT+09:00) Yakutsk</option>
<option value="72" gmtAdjustment="GMT+09:30" useDaylightTime="0" timeshift="9.5">(GMT+09:30) Adelaide</option>
<option value="73" gmtAdjustment="GMT+09:30" useDaylightTime="0" timeshift="9.5">(GMT+09:30) Darwin</option>
<option value="74" gmtAdjustment="GMT+10:00" useDaylightTime="0" timeshift="10">(GMT+10:00) Brisbane</option>
<option value="75" gmtAdjustment="GMT+10:00" useDaylightTime="1" timeshift="10">(GMT+10:00) Canberra, Melbourne, Sydney</option>
<option value="76" gmtAdjustment="GMT+10:00" useDaylightTime="1" timeshift="10">(GMT+10:00) Hobart</option>
<option value="77" gmtAdjustment="GMT+10:00" useDaylightTime="0" timeshift="10">(GMT+10:00) Guam, Port Moresby</option>
<option value="78" gmtAdjustment="GMT+10:00" useDaylightTime="1" timeshift="10">(GMT+10:00) Vladivostok</option>
<option value="79" gmtAdjustment="GMT+11:00" useDaylightTime="1" timeshift="11">(GMT+11:00) Magadan, Solomon Is., New Caledonia</option>
<option value="80" gmtAdjustment="GMT+12:00" useDaylightTime="1" timeshift="12">(GMT+12:00) Auckland, Wellington</option>
<option value="81" gmtAdjustment="GMT+12:00" useDaylightTime="0" timeshift="12">(GMT+12:00) Fiji, Kamchatka, Marshall Is.</option>
<option value="82" gmtAdjustment="GMT+13:00" useDaylightTime="0" timeshift="13">(GMT+13:00) Nuku'alofa</option>
</select>

<input type="submit" name="submit" timeshift="Submit">




Answer Source

Instead of sending all that data along with the form, just send the timeZone value 1 or 2 etc. along with the form. The idea is, maintain a timeZone array like this:

$timeZoneData = array(
    1 => array(
        'gmtAdjustment' => "GMT-12:00",
        'useDaylightTime' => "0",
        'timeshift' => "-12"
    ),
    2 => array(
        'gmtAdjustment' => "GMT-11:00",
        'useDaylightTime' => "0",
        'timeshift' => "-11"
    )
    ...
);

Note: Keys in the array are the timeZone values i.e whatever is there in the value attribute of <option>s.

And refactor your form like this:

<form method="GET" action="">
    <select name="TZ">
        <option value="1">(GMT-12:00) International Date Line West</option>
        <option value="2">(GMT-11:00) Midway Island, Samoa</option>
        ...
    </select>
  ...
</form>

This way, when you select a particular timeZone value from the dropdown list and submit the form, you can easily get all the timeZone details from $timeZoneData array, like this:

if(isset($_GET['submit'])){
    $gmtAdjustment = $timeZoneData[$_GET['TZ']]['gmtAdjustment'];
    $useDaylightTime = $timeZoneData[$_GET['TZ']]['useDaylightTime'];
    $timeshift = $timeZoneData[$_GET['TZ']]['timeshift'];

    ...
}