Form Submit Var Doesn’t Exist When You Use Enter Key To Submit Form
Posted on 24 February 2010
I hope the title is clear enough to help people search for this.
I’ve spent the last few days creating an application for myself to keep track of services performed and clients. I was making a simple “client search” form when I found I was getting inconsistent DB results. Sometimes the results would show up, sometimes not. I won’t go into the full story and how ridiculously long it took me to notice that I wasn’t submitting the form the same way every time. Sometimes I clicked the submit button, sometimes I just hit Enter.
I was invoking the search function based on a cfif tag.
Originally I’d coded this:
<cfif isDefined("FORM.Submit")>
<cfinvoke component="client_tracking.functions.dbactions" method="searchclients" search=#FORM.search#>
</cfif>
I did a relatively extended Google search since I wasn’t entirely sure how to word the question properly, but eventually I discovered a better way of checking if the form had been submitted.
Namely:
<cfif structKeyExists(form, "search")>
<cfinvoke component="client_tracking.functions.dbactions" method="searchclients" search=#FORM.search#>
</cfif>
This new code checks the form structure and the search key to check if it has value. It works both clicking the submit button and hitting the enter key.
Thanks for Ray Camden for having this figured out ages ago.

Instead of checking for FORM.Submit, create a hidden field with an ID of “pageMode” (or something similar) and a value of “process” (or something similar) … then, once the page has submited, check for:
<cfif isDefined("pageMode") and form.pageMode eq "process">Make sense? That way, when you submit the form, you’re looking for a variable within the form that was submitted, not the form submission itself.