2以一种形式提交按钮 [英] 2 Submit buttons in 1 form
问题描述
我的表单中有2个提交按钮。
I have 2 submit buttons in my form.
<input type="submit" value="Save as Draft">
<input type="submit" value="Save">
基本上,我想要做的是用户单击另存为草稿
,它将继续将所有表单详细信息带到 _update.cfm
(未经验证),并且当用户单击保存
,它将进入 _validate.cfm
,然后进入 _update.cfm
(
Basically, what I want to do is when the user clicks on Save as Draft
, it will proceed to bring all the form details to _update.cfm
(without validating) and when the user clicks on Save
, it will proceed to _validate.cfm
and then to _update.cfm
(validating and updating the database.)
HTML:
<cfset tx_name = "">
<cfif isDefined("form.tx_name")>
<cfset tx_name = form.tx_name>
</cfif>
<cfinclude template="_validate.cfm">
<cfif isDefined("form.tx_name")>
<cfinclude template="_update.cfm">
</cfif>
<form name="something">
<input type="text" name="tx_name" value="#tx_name#">
<input type="submit" value="Save as Draft">
<input type="submit" value="Save">
</form>
因此,上述形式基本上是默认情况下的 tx_name = ,当用户键入内容并提交时,它将在
_validate.cfm
中进行所有验证,然后继续进行 _update.cfm
进行更新。
So basically what the above form does is that, by default, tx_name = " "
and when user types something and submits, it will do all the validation in _validate.cfm
and then proceed to _update.cfm
to update it.
这是用户单击保存时的预期工作方式。 code>按钮。但是,对于
另存为草稿,
我希望它跳过 _validate.cfm
并直接携带所有表单字段数据到 _update.cfm
。
This is the intended way to work when the user clicks on Save
button. However, for Save as Draft,
I would like it to skip the _validate.cfm
and straight bring all the form field data to _update.cfm
.
以下是我尝试过的操作:
The following is what I tried:
尝试1:
而不是使用< input type = submit value =另存为草稿>
,我使用了< input type = button value =另存为草稿 onClick = location.href ='_ update.cfm';
。而且这没有将表单字段带到 _update.cfm
,我知道了原因,因为它只是重定向到 _update.cfm
单击按钮。
Instead of having <input type="submit" value="Save as Draft">
, I used <input type="button" value="Save as Draft" onClick="location.href='_update.cfm';"
. And this didn't bring the form fields to _update.cfm
and I figured out the reason, its because it is just redirecting to _update.cfm
upon clicking the button.
所以这让我觉得我真的需要提交
按钮(将表单数据带到_update.cfm页面)。
So this made me think that I really need a submit
button (to bring form data to the _update.cfm page).
但是这里是我迷路的地方,因为我现在有2个提交按钮。其中之一是与 _validate.cfm
一起使用,另一项与 _validate.cfm
一起使用。
But here is where I am lost as I have now 2 submit buttons. 1 of it is to work with _validate.cfm
and the other to work without _validate.cfm
.
所以我要如何使另存为草稿
不是验证而是更新并保存
进行验证和更新?
So how do I go about to make Save as Draft
not validate but update and Save
to validate and update?
推荐答案
为此,您必须为两个提交按钮添加名称。并且使用该名称可以防止_validate.cfm包含在内,同时通过单击另存为草稿按钮提交表单。
For that you have to add name for the two submit buttons. And using that name we can prevent the _validate.cfm inclusion, while submitting the form through clicking "Save as draft" button.
此外,表单方法应为 POST
,以便在操作页面上可以使用表单范围,否则为
Also the form method should be POST
, so that form scope will be available on action page, otherwise it'll available in URL scope.
<cfset tx_name = "">
<cfif isDefined("form.tx_name")>
<cfset tx_name = form.tx_name>
</cfif>
<cfif isdefined("form.Save")>
<cfinclude template="_validate.cfm">
</cfif>
<cfif isDefined("form.tx_name")>
<cfinclude template="_update.cfm">
</cfif>
<form name="something" method="post">
<input type="text" name="tx_name" value="#tx_name#">
<input type="submit" name="SaveAsDraft" value="Save as Draft">
<input type="submit" name="Save" value="Save">
</form>
这篇关于2以一种形式提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!