了解如何使用输入类型=提交表单发送多个值

发布于 2024-10-26 11:01:44 字数 996 浏览 2 评论 0原文

一些背景:我正在开发一个成员目录页面,该页面显示从 MySqL 数据库收集的成员信息。我有一个循环设置为显示每个成员的姓名、id#、标题等 - 每行一个成员。显示的成员列表可以搜索和排序,因此长度为 0-20 个条目(每页最多 20 个)。

可以单击每个成员的姓名,然后显示与其相关的更多信息。例如,如果用户单击“John Doe”的名字,则会包含 John 的“个人信息”页面,从而分割姓名列表(该信息直接包含在他的名字列表之后,但在下一个成员列表之前 - [“John Doe,#333”/“Jane,#777”] 变为“John Doe,#333 / {John 毕业于...}”/“Jane,#777”])。

我目前使用 PHP 填充我的页面,因此列表位于表单内部,并且它们的名称显示为输入,因此当用户单击它们时,会运行表单操作 ($self)。我将表单值设置为成员的姓名,以便用户可以看到可读的名称。我将输入的名称设置为成员的 id# 并在循环内运行 if(isset($_POST['userID']) 以确定显示哪个成员的个人信息。因此,循环运行 MySQL 查询,显示名称,id... 对于每个成员,如果 curID# == $_POST['userID'],它还会显示相应的个人信息

我的问题: 我遇到的问题是我的列表在页面上相当长,特别是显示个人信息,因此我希望能够使用与其 ID# 相对应的锚点跳转到页面上的成员信息。我设置了锚点,我可以手动导航到 memList.php#ID333,但我想当用户单击名称时导航到那里。

我可以设置表单操作以导航到 $self#$curID,但 $curID 是成员名称输入的变量名称,而不是它的值

。 :我尝试使用 ID 作为值和 curiD 作为名称的隐藏字段,但它们不起作用,因为我的循环为每个成员重置它(因此, $_POsT['curid'] 始终设置为最底部成员,而不是用户单击的成员)。

我已将名称作为 href 链接,但随后我的搜索和排序 $POST 值不会重新发送(页面基本上从一开始就刷新)。

我的问题,速记:有什么方法可以设置一个输入字段来显示成员的姓名,同时将他们的 ID 作为值发送吗?

Some background: I'm working on a member directory page which displays member information gathered from a MySqL database. I have a loop set to display name, id#, title, etc from each member - one member per row. The displayed member list can be searched and sorted so will be anywhere from 0-20 entries long (20 max per page).

Each member's name can be clicked and more information pertaining to them is displayed. For example, if the user clicks on "John Doe"'s name, an "individual info" page for John is included, splitting the list of names (the info is included directly after his name's listing, but before the next member's listing - ["John Doe, #333" / "Jane, #777"] turns into "John Doe, #333 / {John is a graduate from...}" / "Jane, #777"]).

I currently populate my page with PHP so the list is inside of a form and their names are displayed as inputs so when the user clicks them, the form action ($self) is run. I have the form value set to the member's name so that users can see readable names. I have the input's name set to the member's id# and run a if(isset($_POST['userID']) inside my loop to determine which member's individual information is displayed. So, the loop runs through the MySQL query, displaying name,id... for each member and if curID# == $_POST['userID'], it also displays the corresponding individual information.

My Issue: The problem I'm encountering is that my list is rather long on the page, especially with individual information displayed so I want to be able to jump to the member's info on the page using anchors corresponding to their ID#. I have the anchors set up, I can manually navigate to memList.php#ID333, but I want to navigate there when the user clicks on the name.

I can set up my form action to navigate to $self#$curID, but $curID is the variable name for the member's name input, not the value of it.

What Hasn't Worked: I've attempted hidden fields with their ID as the value and curiD as the name, but they do not work because my loop resets it for every member (hence, $_POsT['curid'] is always set to the bottom-most member, not the one the user clicked).

I've had the names as href links, but then my search and sort $POST values are not resent (the page is basically refreshed from the start).

My Question, Shorthand: Is there any way I can setup an input field to display a member's name, yet have their ID sent as the value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年 2024-11-02 11:01:44

如果我理解正确的话,这听起来最好使用 javascript 自动完成器来完成。如果您使用 jQuery,此处是其自动完成插件的链接。查看演示,看看这种方法是否适合您的需求。

If I understood correctly, this sounds like something that would be best done using a javascript autocompleter. If you're using jQuery, here is a link to their autocomplete plugin. Check out the demo and see if this kind of approach suits your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文