简体   繁体   English

需要有关通过带有 select 框的表单提交值的帮助吗?

[英]Need help regarding submitting values through a form with select Box?

I have a empty select box on a form.我在表格上有一个空的 select 框。

<select id='essentialDocs[]' ></select>

through some script i add options to it.通过一些脚本,我向它添加了选项。 Basically it adds URL's.基本上它添加了 URL。 So at runtime html will look like所以在运行时 html 看起来像

<select id='essentialDocs[]' >
<option value='http://www.google.com' title='Google'>Google</option> 
<option value='http://www.yahoo.com' title='yahoo'>Yahoo</option>
</select>

Now on submitting the form i want to get both of these key:value pairs现在在提交表单时,我想同时获得这两个键:值对

like Title:URL google:http://www.google.com喜欢标题:URL 谷歌:http://www.google.com

but on doing $_POST['essentialDocs'] i only get values and not title's.但是在做$_POST['essentialDocs']我只得到值而不是标题。 What modification would help get me both.什么修改会帮助我得到两个。 Also another thing i have on the form is i can switch the ordering of url's on screen.我在表格上的另一件事是我可以在屏幕上切换 url 的顺序。 Please suggest some solution请提出一些解决方案

If you need the title map the title to the URL on the server in eg A dictionary or array .如果您需要title map title服务器上URL ,例如 A dictionaryarray

IMHO it would be even better to do it the other way around.恕我直言,反过来做会更好。 Set the title as a value and map it to a URL on the server.将标题设置为一个值,并将 map 设置为服务器上的 URL。

  $arr["Google"] ='http://www.google.com'
  $arr["yahoo"] = 'http://www.yahoo.com' 

then you also have the ability to maintain this array on the server and echo it (back) into the select.那么您还可以在服务器上维护此阵列并将其回显(返回)到 select 中。

more here更多在这里

Try this.尝试这个。 This may help you..这可能会帮助你..

Just add title in value with: When you submit you get your desire value.只需在价值中添加标题:当您提交时,您将获得您想要的价值。

<form method="post" action="">
  <select id='essentialDocs[]' name='list'>
    <option value='google:http://www.google.com' title='Google'>Google</option> 
    <option value='yahoo:http://www.yahoo.com' title='yahoo'>Yahoo</option>
  </select>
  <input type="submit" name="Submit" value="submit">
</form>

Print post array in PHP在 PHP 中打印帖子数组

<?php 
  print_r($_POST);
?>

Output: Output:

Array ( [list] => yahoo:http://www.yahoo.com [Submit] => submit ) 

Now you can get both title and URL.现在您可以获得标题和 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM