如果SELECT表单与OPTIONS在提交时如何传递多个参数?

时间:2017-08-15 20:55:07

标签: javascript php html forms

我有一个简单的HTML表单,其中包含select和options,可以发送Timezones详细信息。

提交表单时,我想传递/发送多个值。 我找到了不同的approches示例,但没有一个完全符合我的需要。

  • 目前,下面的表单只能发送1个参数作为值: 假设已经提交了第一个选项,这里的值send是时区ID:1

即:

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

希望你能帮助我找到一个简单的方法,使用PHP或Javascript传递超过GET表单的参数。

<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">

1 个答案:

答案 0 :(得分:1)

不要将所有 数据与表单一起发送,只需将timeZone值server { listen 80; server_name server_name www.domain.com domain.com; location / { root /var/www/html; index index.php index.html index.htm; } location ~ \.php$ { root /var/www/html; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 1等与表单一起发送即可。这个想法是,维护一个像这样的timeZone数组:

2

注意:数组中的键是timeZone值,即$timeZoneData = array( 1 => array( 'gmtAdjustment' => "GMT-12:00", 'useDaylightTime' => "0", 'timeshift' => "-12" ), 2 => array( 'gmtAdjustment' => "GMT-11:00", 'useDaylightTime' => "0", 'timeshift' => "-11" ) ... ); 的{​​{1}}属性中的任何值。

并像这样重构你的表格:

value

这样,当您从下拉列表中选择特定的timeZone值并提交表单时,您可以轻松地从<option>数组中获取所有timeZone详细信息,如下所示:

<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>