title: Testing for existence of FORM scope / struct in ColdFusion
body: <p>Problem: When requesting the <a href="http://en.wikipedia.org/wiki/Web_Services_Description_Language" rel="nofollow noreferrer">WSDL</a> for a <a href="http://en.wikipedia.org/wiki/ColdFusion#ColdFusion_Components_.28Objects.29" rel="nofollow noreferrer">CFC</a>, I get the following error: <b>Variable FORM is undefined</b>. It happens in this line of code, in the OnRequestStart method in application.cfc</p>
  
  <pre><code>&lt;cfif structKeyExists(form,'resetappvars')&gt;
      &lt;cfset OnApplicationStart() /&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>If I request a specific method, it works fine. I have considered using cfparam to create a default form struct if none exists, but that seems like an ugly hack and I worry it will actually create the form struct in the variables or this scope of the CFC. Maybe this is a legitimate bug as well?</p>
  
  <p><b>Note:</b> This only happens when I request the WSDL, if I invoke a method directly - the code executes as expected without problems.</p>
  
  <p><b>Update:</b> Application.cfc code sample - just add any CFC to your app and request it with <code>?wsdl</code> to see the issue. This has been tested (and failed) on ColdFusion 7 and ColdFusion 8.</p>
  
  <pre><code>&lt;cfcomponent output="false"&gt;
  
      &lt;cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false" hint="Fires when the application is first created."&gt;
          &lt;cfset application.dsn = "my_dsn" /&gt;
          &lt;cfreturn true /&gt;
      &lt;/cffunction&gt;
  
      &lt;cffunction name="OnRequestStart" access="public" returntype="boolean" output="false" hint="Fires at first part of page processing."&gt;
          &lt;cfargument name="TargetPage" type="string" required="true" /&gt;
          &lt;cfif structKeyExists(form,'resetappvars')&gt;
              &lt;cfset OnApplicationStart() /&gt;
          &lt;/cfif&gt;
          &lt;cfreturn true /&gt;
      &lt;/cffunction&gt;
  &lt;/cfcomponent&gt;
  </code></pre>