0

2 つの異なる送信ボタンを使用しようとしています。1 つの送信ボタンが押されると 1 つの CGI スクリプトに移動し、もう 1 つのボタンが押されると別の 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>'
4

2 に答える 2

1

1つの解決策は、どの送信ボタンがクリックされたかに基づいて実行するスクリプトを決定する中間スクリプトにフォームを投稿することです。

したがって、の値Submit1が指定されている場合は、スクリプトAを実行します。の値Submit2が指定されている場合は、スクリプトBを実行します。

于 2012-12-13T16:47:19.583 に答える