在cherrypy点击链接提交表单

时间:2016-08-11 06:04:08

标签: python cherrypy

以下是我的代码:

class MyApp:
    def link_details(self, **params):
        pass
    link_details.exposed=True

以下是我的HTML代码:

<form name="form1">
<input type="text" name="username"> <a href="link_details">Click here</a>
</form>

页面被重定向,但我无法访问表单请求参数。我希望在单击html页面中的链接时将表单提交给link_details方法。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

您没有提交表单,只是链接到其他页面。

提交表单最简单的方法是使用提交按钮:

<form id="form1" action="/link_details" method="post">
    <input type="text" name="username" />
    <input type="submit" value="Submit" />
</form>

如果您想使用<a>标记提交表单:

<form id="form1" action="/link_details" method="post">
    <input type="text" name="username" />
    <!-- you can omit the "return false;" part, but since we don't use a "href" attribute on the anchor it does not matter -->
    <a onclick="document.getElementById('form1').submit();return false;" target="_self">Submit</a>
</form>

有关表单属性的更多信息(例如actionmethod),请访问https://developer.mozilla.org/de/docs/Web/HTML/Element/form

相关问题