我可以将 Drupal 表单中的第二个或后续按钮设置为默认按钮吗?
我在使用 Form API 构建的自定义 Drupal 6 模块中有一个表单,它在列表中有 1 个或多个 image_button 元素,后跟“保存”和“取消”按钮。
单击图像和标准按钮时一切正常,它们调用了它们应该调用的提交函数,但是如果我在表单中的任何文本字段中按 [ENTER] 键,则会提交表单中的第一个按钮,不幸的是本例是列表中的 image_button 而不是 Save 按钮。
这是 Web 表单的一个标准问题,您通常必须在表单定义的早期隐藏一个隐藏的(按样式和/或大小)按钮,以确保调用默认提交路径(在这种情况下,这就是“保存”按钮将调用的路径) ),而不是您希望成为默认按钮之前的按钮的提交路径。
是否有一些 Drupal 6 魔法可以设置默认按钮,无论它在文档中找不到的表单定义中的位置,或者我应该创建一个样式为不可见的虚拟提交按钮?
预先感谢您的任何答复。
I have a form in a custom Drupal 6 module built with the Form API, it has 1 or more image_button elements in a list followed by the Save and Cancel buttons.
Everything is working fine when clicking the image and standard buttons, they call the submit functions they should, but if I hit the [ENTER] key within any of the text fields in the form the first button in the form is submitted, which unfortunately in this case is an image_button in the list rather than the Save button.
This is a standard problem with web forms, you generally have to hack in a hidden (by style and/or size) button early in the form definition to ensure the default submit path is called (in this case that's what the Save button will call) rather than the submit path for the buttons that are before the button you want to be the default.
Is there some Drupal 6 magic that enables setting a default button regardless of where it is in the form definition that I've failed to find in the docs, or should I create a phantom submit button that is styled to not be visible?
Thanks in advance for any answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将
'#weight'
添加到您的按钮上。Try to put
'#weight'
to your buttons.答案似乎是否定的,没有内置的 Drupal 方法可以解决按 [ENTER] 时默认表单中的第一个按钮的问题。
这就是我必须做的。
我在表单顶部创建了一个额外的提交按钮:
在页面包含的 CSS 中,我添加了以下带和大括号 CSS,以在我可以测试的尽可能多的 Web 浏览器中隐藏额外的提交按钮:
The answer seams to be no, there is no built in Drupal method of getting around the problem of the first button in a form being the default when pressing [ENTER].
Here is what I had to do.
I created an extra submit button at the top of my form:
In the CSS included for the page I added the following belts and braces CSS to hide the extra submit button in as many web browsers as I could test:
您可以通过为每个提交按钮分配不同的名称来轻松做到这一点
you can easily do this by assigning different names to each submit button