[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

How do I make conditional values in <cfinput> fields?

Hello,
How can I make conditional values using <cfinput> fields?
I normally use a regular input tag with a <cfif> statement inside it, like so:

<input type="text" name="productName" <cfif IsDefined("FORM.productName")> value="#FORM.productName#"</cfif> />

However, when using a <cfinput> tag, you can't nest a <cfif> inside it. :(

I need to use <cfinput> so that I can have form validation (required="yes" validateAt="onServer", etc.), but I need to make the values conditional.

What are my options?
0
chaseivey
Asked:
chaseivey
1 Solution
 
azadisaryevCommented:
use iif() function [http://cfquickdocs.com/cf8/?getDoc=IIf]:

<cfinput type="text" name="productName" value="#iif(structkeyexists(FORM, 'productName'), de(form.productname), de(''))#"  />

another option is to put <cfinput> inside a cfif block:
<cfif structkeyexists(form, 'productname')>
<cfinput type="text" name="productName" value="#form.productname#"  />
<cfelse>
<cfinput type="text" name="productName" value=""  />
</cfif>

Azadi
0
 
_agx_Commented:
A third option is to set a default for the form fields. Then neither IIF or cfif would be needed:

<cfparam name="form.productName" default="">
...

<cfinput type="text" name="productName" value="#FORM.productName#" />
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now