title: Setting a form variable inside the form (coldfusion)
body: <p>I am trying to manually set a variable INSIDE a form, because it contains html and placing it in the value attribute of a  tag would cause errors in the display.  Currently, I check to see if that attribute contained html, and if so, the field is empty.  </p>
  
  <p>I'd like to be able to set the variable as the old value if it contained html in previous entries of the form, so that the user wouldn't have to enter that field every time they loaded that ORM object to edit.</p>
  
  <p>Here's a snippet:</p>
  
  <pre><code>&lt;cfif ("#dataobject.getField()#" NEQ "" AND Left(dataobject.getField(), 1) EQ "&lt;")&gt;
  &lt;cfscript&gt;
      temp = dataobject.getField();
      temp2=temp;
      temp2 = Insert("---", temp2, 0);
      temp2 = Insert("&lt;!", temp2, 0);
      temp2 = Insert("---&gt;", temp2, Len(temp2));
      dataobject.setField(temp2);                             
  &lt;/cfscript&gt;
  
  &lt;label for="name"&gt;
      Field:
  &lt;/label&gt;
  &lt;input type="text" name="Field" value=""&gt;
  &lt;button id="savefield" name="savefield"&gt;Save&lt;/button&gt;
  &lt;cfif form.Field EQ ""&gt;&lt;cfset form.Field = temp&gt;&lt;/cfif&gt;
  &lt;cfscript&gt;
      dataobject.setField(temp);
  &lt;/cfscript&gt;
  
  &lt;cfelse&gt;
  &lt;label for="name"&gt;
      Field:
  &lt;/label&gt;
  &lt;input type="text" name="Field" &lt;cfif ("#dataobject.getField()#" NEQ "")&gt;value="#dataobject.getField()#"&lt;/cfif&gt;&gt;
  &lt;button id="savefield" name="savefield"&gt;Save&lt;/button&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>The code I was trying to use:
  <code>&lt;cfif form.Field EQ ""&gt;&lt;cfset form.Field = temp&gt;&lt;/cfif&gt;</code></p>
  
  <p>Coldfusion throws an error saying that the FORM variable is undefined (which doesn't surprise me).  The "savefield" button calls javascript that opens a window allowing the user to set the value, then closes.  Should I put my code there instead?</p>
  
  <p>-The inserts which turn the string into a comment was an early attempt at a workaround that didn't work :/</p>