具有更多提交和回车提交的表单
这个问题在某种程度上类似于这个。
我的电子商务解决方案中有一个表单。当您将商品放入购物车时,您可以更改商品数量。推车是一个整体。该表单有两个提交按钮 - 重新计算和继续(这将引导买家进入流程的第 2 步)。
当用户使用输入更改项目数量时,他可以点击重新计算(将帖子发送到应用程序,这将更改会话/数据库中的数字)或继续(这还将发送帖子数据以重新计算,然后将用户带到步骤2)。
但是当用户按下 Enter 键时,重新计算按钮优先。
我想要的是让重新计算按钮提交表单,但仅在单击时提交,而不是在按 Enter 提交时提交。相反,“继续”按钮也应该与 Enter 一起使用。
该解决方案不得使用 javascript,因为前端必须在不启用 JS 的情况下可用。
有什么想法吗?
This question is somehow similar to this one.
I have a form in my ecommerce solution. When you insert something into the cart, you can change number of items. The cart is whole in one form. The form has two submit buttons - recalcualte and continue (which will take buyer to Step 2 of the process).
When user changes the number of items using the inputs, he can either hit recalculate (which sends post to app that will change the numbers in session/db) or continue (that will also send the post data to recalculate and then take user to the step 2).
But when user hits enter, the recalculate button takes precedence.
What I want is to make the recalculate button submit the form, but ONLY when clicked and NOT when submited by pressing enter. In contrast the "continue" button should work also with enter.
The solution MUST NOT use javascript as the frontend has to be useable without JS enabled.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够决定服务器端。单击按钮时,会提交名称-值对,但按下
return
时不会提交。因此,更改服务器端脚本以在提交重新计算名称值时执行“重新计算”,并在所有其他情况下继续执行。You should be able to decide that server-side. When a button is clicked it's name-value pair is submitted, but when
return
is pressed it isn't. So change your server-side script to do "recalculate" when the recalculate name-value is submitted and to contine in all other cases.将优先级最高的按钮放在 html 源代码中,并使用标记来反转两个按钮的位置?
编辑:你说你的布局无法处理这个问题。
任何一个:
1.改变布局。功能性更重要,对于布局来说,实现它的方法不止一种。
2. 让表格不检查是否按下了“重新计算”或“提交”,而是检查显示的价格与计算的奖金是否正确。示例:
用户购买 1 件商品,价值 3 美元。
用户购买 2 件商品,价值 5 美元。
总奖金:13美元。
用户现在将 1 项更改为 4 项。 3 美元变成了 12 美元,但他没有点击重新计算。
在表单中设置一个显示总金额的字段(隐藏字段最好)。当用户提交表单时,重新进行计算。如果计算出的奖金等于隐藏字段中的奖金,则用户知道最终的正确奖金。如果不同,请重新显示表格,并注明“您更改了购物车,总奖品已更新以反映这些更改。验证金额并提交购买”或其他内容。
Put the button that takes precedence first in your html sourcecode, and use markup to invert the position of the two buttons?
Edit: you say your layout can't handle that.
Either:
1. Change the layout. Functionality is more important, and for layout there is more than one way to do it.
2. Have the form not check if "recalculate" or "submit" was pressed, but rather if the shown price was correct with the calculated prize. Example:
User buys 1 item, value 3 dollar.
User buys 2 items, value 5 dollar.
Total prize: 13 dollar.
User now changes the 1 item into 4 items. 3 dollar becomes 12 dollar, but he doesn't hit recalculate.
Have a field in your form that shows the total amount (a hidden field is nicest). When the user submits the form, redo the calculation. If the calculated prize equals the prize in the hidden field, the user knew the final correct prize. If it differs, reshow the form mentioning "You changed your shopping cart, the total prize has been updated to reflect these changes. Verify the amount and submit to purchase" or something.