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.
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.
Here's a snippet:
<cfif ("#dataobject.getField()#" NEQ "" AND Left(dataobject.getField(), 1) EQ "<")>
<cfscript>
temp = dataobject.getField();
temp2=temp;
temp2 = Insert("---", temp2, 0);
temp2 = Insert("<!", temp2, 0);
temp2 = Insert("--->", temp2, Len(temp2));
dataobject.setField(temp2);
</cfscript>
<label for="name">
Field:
</label>
<input type="text" name="Field" value="">
<button id="savefield" name="savefield">Save</button>
<cfif form.Field EQ ""><cfset form.Field = temp></cfif>
<cfscript>
dataobject.setField(temp);
</cfscript>
<cfelse>
<label for="name">
Field:
</label>
<input type="text" name="Field" <cfif ("#dataobject.getField()#" NEQ "")>value="#dataobject.getField()#"</cfif>>
<button id="savefield" name="savefield">Save</button>
</cfif>
The code I was trying to use:
<cfif form.Field EQ ""><cfset form.Field = temp></cfif>
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?
-The inserts which turn the string into a comment was an early attempt at a workaround that didn't work :/