> And lo and behold, it worked.
>
Well it *kinda* works. The resultant <input> tag is
malformed:
<input name="tControlName" type="text" value="Some string
value""
id="tControlName" type="text" value="Some string value""
type="text" />
Note the double up of a couple of the double-quotes, which
means there is
this bit in the middle of your tag - " id="tControlName"
type="text"
value="Some string value"" - which invalidates the mark-up.
If you look at what <cfinput> is doing, it makes a
matching NAME and ID
attribute for the <input> out of the NAME attribute of
the <cfinput>
So you end up with:
<input
name="
tControlName" type="text" value="Some string value"
"
id="
tControlName" type="text" value="Some string value"
"
/>
Which results in the double-up of attributes, as well as the
incorrect
usage of double-quotes. Both these invalidate the tag. I'm
actually
surprised it renders. Browsers are forgiving these days. I
wonder what
Opera would make of it (as I believe it's a bit less
forgiving than IE or
Firefox).
However you CAN achieve a working example of this by
"spoofing" one of the
other attributes of <cfinput>, as this example
demonstrates:
<cfset spoofSize='40" maxlength="10" value="fieldValue"
tabindex="1'>
<cfform name="fTest" method="post" action="">
<cfinput name="formField" size="#spoofSize#" />
</cfform>
So you end up with this:
<input
name="formField"
id="formField"
type="text"
size="
40" maxlength="10" value="fieldValue" tabindex="1
"
/>
This parses as valid HTML.
However this all is no help to you. You were wanting to
dynamically set
the specific <cfinput> attributes weren't you (which
effect validation and
that sort of carry-on)? Not the basic HTML attributes which
are simply
passed-through. If you just wanted to do this with the HTML
attributes,
there's not need to be using <cfinput>, and indeed you
could dynamically
build your <input> tag thus:
<cfset otherAttributes='size="40" maxlength="10"
value="fieldValue"
tabindex="1"'>
<cfoutput>
<input name="formField" id="formField" type="text"
#otherAttributes# />
</cfoutput>
This outputs:
<input name="formField" id="formField" type="text"
size="40" maxlength="10"
value="fieldValue" tabindex="1" />
You CANNOT spoof <cfinput>-specific attributes such as
"required", "mask",
"validate", etc. They'll simply get treated as "noise", and
passed through
to STDOUT (to re-use yesterday's euphemism).
Make sense?
--
Adam