我正在使用web2py编写一个类似于搜索引擎的应用程序。是否可以实现一个表单中的两个提交按钮,例如谷歌有两个按钮“搜索”和“I'm feeling lucky”。提前感谢您的帮助。
类似这样的:
def search():
form = FORM(INPUT(_type='text', _name='keywords'),
INPUT(_type='submit', _value='Search'),
INPUT(_type='submit', _value="I'm feeling lucky", _name='lucky'),
_method='get')
if request.vars.keywords:
if request.vars.lucky:
[code to return "I'm feeling lucky" results]
else:
[code to return regular results]
return dict(form=form)
参考:https://groups.google.com/forum/#!topic/web2py/a0hoswzJBYY提供了一个解决方案,当使用SQLFORM.factory
助手而不是FORM
助手时。
如果传入请求中包含按下按钮的名称,则可以实现。
$_POST
数组是否包含以按下按钮的名称命名的键来找到已按下哪个按钮(在多按钮表单中)。在webpy中是否有类似于$_POST
数组的东西? - Nadir Sampaoli