最佳实践:多种形式

发布于 2024-12-06 02:54:16 字数 295 浏览 0 评论 0原文

当每个表单执行不同的操作时,在 HTML 文档中包含多个表单是否被认为是最佳实践?这就是我正在做的事情:我正在创建一个搜索页面,它将使用几个不同格式的 SQL 查询来查询我的数据库。该页面有三种搜索类型,每种搜索类型都有简单模式和高级模式。目前,我使用 javascript 隐藏除活动表单之外的所有表单,并且我将每种搜索模式以各自的表单彼此分开,因为我以不同的方式处理它们。单击搜索按钮后,搜索结果将发布在搜索表单下方的同一页面上。

那么,通常认为最好的做法是使用多种表单(这使得其结构更容易、更模块化),还是我应该简单地隐藏和取消隐藏一个复杂表单内的元素?

Is it considered best practice to have multiple forms in an HTML document when each of those forms performs a different action? Here's what I'm doing: I am making a search page that will query my database with several differently formulated SQL queries. This page has three types of search, and each type of search has a simple and an advanced mode. At present, I use javascript to hide all of the forms except the one that is active, and I keep each mode of a search separate from each other in their own forms because I handle them differently. When the search button is clicked, the results of the search will be posted on the same page below the search forms.

So, is it generally considered to be best practice that one would do this with multiple forms (which makes it easier and more modular in it's structure) or should I simply hide and un-hide elements inside of one complex form?

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

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

发布评论

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

评论(2

戈亓 2024-12-13 02:54:16

当每个表单执行不同的操作时,在 HTML 文档中包含多个表单是否被认为是最佳实践?

答案:仅当这些表单转到单独的 URL 时。

这就是我正在做的事情:我正在创建一个搜索页面,它将使用几个不同格式的 SQL 查询来查询我的数据库。
该页面有三种搜索类型,每种搜索类型都有简单模式和高级模式。
目前,我使用 javascript 隐藏除活动表单之外的所有表单,并且我将每种搜索模式以各自的表单彼此分开,因为我以不同的方式处理它们。
单击搜索按钮后,搜索结果将发布在搜索表单下方的同一页面上。

从您模糊的描述来看,重复代码的可能示例:

<form id="search-type-1" action="/search-engine" method="post">
    <input type="checkbox" name="advanced-mode" /> - Advanced
    <input type="text" name="query" />
    <div class="options">
        Put advanced options here.
    </div>
</form>
<button id="submit-button">Search</button>
<div id="search-ouput"></div>

那么,通常认为使用多种形式执行此操作是最佳实践(这使得其结构更容易且更模块化),还是我应该简单地隐藏和取消隐藏一种复杂形式中的元素?

回答:这似乎过于复杂。我想说这不是最佳实践。有了更多信息,我相信有人可以向您展示更好的方法。

Is it considered best practice to have multiple forms in an HTML document when each of those forms performs a different action?

answer: Only if those forms go to separate URLs.

Here's what I'm doing: I am making a search page that will query my database with several differently formulated SQL queries.
This page has three types of search, and each type of search has a simple and an advanced mode.
At present, I use javascript to hide all of the forms except the one that is active, and I keep each mode of a search separate from each other in their own forms because I handle them differently.
When the search button is clicked, the results of the search will be posted on the same page below the search forms.

Possible example of repeated code, from your vague description:

<form id="search-type-1" action="/search-engine" method="post">
    <input type="checkbox" name="advanced-mode" /> - Advanced
    <input type="text" name="query" />
    <div class="options">
        Put advanced options here.
    </div>
</form>
<button id="submit-button">Search</button>
<div id="search-ouput"></div>

So, is it generally considered to be best practice that one would do this with multiple forms (which makes it easier and more modular in it's structure) or should I simply hide and un-hide elements inside of one complex form?

Answer: This seems overly complex. I would say this is NOT best practice. With more info, I'm sure someone could show you a much better way.

凯凯我们等你回来 2024-12-13 02:54:16

在页面上呈现表单被认为是最佳实践,使其目的直观明显、易于访问者使用、具有良好的可供性,并且(在我看来)它们在页面上看起来很好。这个问题会引起很多相互矛盾的意见,但每个人至少可以在这四点上达成一致(是的,surrrrrre!)。

很多人可能会说“好吧,最好向左浮动”或“在此处使用

    ”或“为什么position:fixed;?”在我看来,这些担忧远不如访问者对完成页面的反应那么重要。

It is considered best practice to present forms on the page such that their purpose is intuitively obvious, they are easy for the visitor to use, they have good affordance, and (imo) they look well on the page. This question invites lots of contradictory opinions, but it could be (yeah, surrrrrre!) that everyone can agree on those four points at least.

Lots of folks can say "well, it's better to float this left" or "use a <ul> here" or "why position:fixed;?" IMO, these concerns are all way, way less important than the visitor's reaction to the finished page.

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