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

How do I tell which form button was clicked

Guest
May 11, 2006 May 11, 2006
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
394
Translate
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>







Translate
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>







Translate
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
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.">

Translate
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