我尝试有两个不同的提交按钮。如果按下一个提交按钮,它将转到一个cgi脚本,如果按下另一个按钮,它将转到另一个cgi脚本。下面是我的代码,但它没有按我所希望的那样工作。无论按哪个脚本,它们都只转到同一个脚本。在
#!/usr/bin/env python
import cgi
import cgitb
cgitb.enable()
form = cgi.FieldStorage()
keyword = form.getvalue('keyword')
keyset = set(x.strip() for x in open('keywords.txt', 'r'))
print 'Content-type: text/html\r\n\r'
print '<html>'
print "Set = ", keyset
print '<h1>If your keyword is in the set, use this submission button to retrieve recent tweets</h1>'
print '<form action="results.cgi" method="post">'
print 'Keyword: <input type="text" name="keyword"> <br />'
print '<input type="submit" value="Submit" name="Submit1" />'
print '</html>'
print 'Content-type: text/html\r\n\r'
print '<html>'
print '<h1>If your desired keyword is not in the set, use this submission button to add it</h1>'
print '<form action="inlist.cgi" method="post">'
print 'Keyword: <input type="text" name="keyword"> <br />'
print '<input type="submit" value="Submit" name="Submit2" />'
print '</html>'
使用调度脚本。这也允许快速进口。 示例:
^{pr2}$
一种解决方案是将表单发布到中间脚本,该脚本根据单击的提交按钮决定运行哪个脚本。在
因此,如果提供了
Submit1
的值,则运行脚本A。如果提供了Submit2
的值,则运行脚本B相关问题 更多 >
编程相关推荐