一个形成两个动作 [英] One form two action
问题描述
您好,我有几个表单字段我想点击按钮的控制被发送到操作1,但
的点击按钮2它必须发送到操作2.目前我使用js以在点击时动态地改变表单动作。但是有什么其他解决方案。
Hi i have a few form fields i want the on click of button a the control to be sent to action 1 but on click of button 2 it has to be sent to action 2. Currently i am using js to change the form action dynamically on click. but is there any other solution. I cant do the checking after submit in a same method thet have to be two different methods.
在这种情况下,2个按钮是视图(需要显示html数据)并下载(与csv文件相同的数据)。我使用cakephp 1.2,但我觉得这更像是一个通用的问题
The 2 buttons in this case are view(html data needs to be displayed) and download(same data as csv file). I am using cakephp 1.2 but i feel this is more of a generic problem
推荐答案
HTML5有 formaction 属性
<form action="/url" id="myForm">
<input type="submit" value="save1" formAction="/url1" />
<input type="submit" value="save2" formAction="/url2" />
</form>
如果需要,这里是备用。
Here is a fallback if you need it.
if (!('formAction' in document.createElement('input'))){
$('form').on('click', 'input[type=submit]', function (e) {
var attr = this.getAttribute('formAction');
if (attr) {
this.action = attr; //Set the form's action to formAction
}
});
}
这篇关于一个形成两个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!