• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do I tell which form button was clicked

New Here ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

I have a CFForm with three buttons on it: a standard reset button, and two submit buttons that will perform different functions depending on which one was clicked. When I go to the action page, how can I tell which button was clicked in order to perform the correct action?
TOPICS
Advanced techniques

Views

305

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 11, 2006 May 11, 2006
<cfform>
<cfinput name="s1" type="submit"...etc>
<cfinput name="s2" type="submit"...etc>
</cfform>

On the action page, do

<cfif isDefined("form.s1")>
s1 submitted
<cfelseif isDefined("form.s2")>
s2 submitted
</cfif>







Votes

Translate

Translate
Community Expert ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

<cfform>
<cfinput name="s1" type="submit"...etc>
<cfinput name="s2" type="submit"...etc>
</cfform>

On the action page, do

<cfif isDefined("form.s1")>
s1 submitted
<cfelseif isDefined("form.s2")>
s2 submitted
</cfif>







Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 11, 2006 May 11, 2006

Copy link to clipboard

Copied

LATEST
Or you can give the buttons the same name with a specific value:

<input type="submit" name="formaction" value="Reserve Date">
<input type="submit" name="formaction" value="Schedule Date">

Form.formaction will return the value of the button clicked. Only thing to be careful about is if the user hits return in a text input box. That would submit the form without a value for formaction.

You could handle that by requiring the button:

<input type="hidden" name="formaction_required" value="Please select an action.">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation