0

I'm sitting on a from trying the Coldfuion XMLFormat() function.

However if I do this:

<form name="sample" action="#cgi.script_name#" method="post">
    <input name="test" value="#XMLFormat( form.test )#" type="text" tabindex="1" />
</form>

I'm just getting CF-erors, that element test is undefined. What am I doing wrong?

Thanks for input!

frequent
  • 27,643
  • 59
  • 181
  • 333

1 Answers1

1

You need to check if form.test exists:

<form name="sample" action="#cgi.script_name#" method="post">
  <input name="test" value="<CFIF structkeyexists(form,"test")>#XMLFormat( form.test )#</CFIF>" type="text" tabindex="1" />
</form>
Seybsen
  • 14,989
  • 4
  • 40
  • 73
  • doesn't like the if-else shorthand - Invalid token ? found... trying CFIF – frequent Apr 28 '12 at 14:41
  • in CF8 I have to , correct? So I'm getting no error with value="#XMLFormat( form.test)#" type="text" /> – frequent Apr 28 '12 at 14:44
  • Ok. Need to fiddle with some more, because I have 3 forms on my page. But more or less works. Thanks again! – frequent Apr 28 '12 at 15:39
  • 2
    Good answers but you (Depending on your logic) you might try just adding some tags above your form as in (or value= some default value). – Mark A Kruger Apr 28 '12 at 17:59
  • @MarkAKruger - I think that just might be it...because all my tests with structkeyexists or isdefined just fail. Is this because I need to "setup" the form fields first, because the form scope will only be available once the form is submitted... (did I get this right...?) – frequent Apr 28 '12 at 21:24
  • No ... you can test for the existence of a Form variable as well - using isDefined() or StructKeyExist() as in the example that Seybsen gave. If you are getting an error it's probably not done right (sorry:). but predefining them works too and is a good idea if you want some defaults to work with. – Mark A Kruger Apr 28 '12 at 21:45