adding a CFIF to a CFINPUT tag

I want to define a CFIF tag insdie a CFINPUT tag to add required=yes everytime that a specific condition was satisified, but CF through an error :

Invalid token 'c' found on line 363 at column 98.  
The CFML compiler was processing:

a cfinput tag beginning on line 363, column 24.
a cfinput tag beginning on line 363, column 24.
 
 
Any idea ?
Michael_OAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pinaldaveCommented:
As per I have experience.
This does not work for me.
What I do here is that...
<cfif my condtion>
<cfinsert with some inserts>
</cfelse>
<cfinsert with more inserts>
</cfif>

Regards,
---Pinal
0
kkhippleCommented:
just as pinal suggested use

<CFIF statement>
  <CFINPUT ... required = "yes" >
<CFELSE statement>
  <CFINPUT ... required = "no" >
</CFIF>
0
mrichmonCommented:
You cannot nest cold fusion tags

But you can use a regular input tag with a nested cfif - which is not what you asked, but is probably a better way to go in the long run - not using cfinput or cfform - but writing actual HTML elements.

<input <cfif ....></cfif>>
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

kkhippleCommented:
if Michael_O ends up writing actual HTML elements, then javascript will be needed for any client validation such as making sure user has filled out a particular input (required = yes).
0
mrichmonCommented:
Yes it would, but it would be more robust, effective, and all around better code.

Notice that I said "in the long run" because this is not a trivial task, but does make you end up with a better application less prone to the bugs in cfform and more user friendly than the automatically written validation for cfinputs.
0
mrichmonCommented:
Note that javascript is needed even with cfinput - COld Fusion just does most of it for you....
0
danrosenthalCommented:
You can also use YESNOFORMAT(), for instance...

<CFINPUT name="test" required="#yesnoformat(testvalue eq 3)#">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mosphatCommented:
You can use iif() to have cfif-like functionality in CF-tags. But if it comes to performance and readability, pinaldave had the correct solution:

<cfif my condtion>
<cfinsert with some inserts>
</cfelse>
<cfinsert with more inserts>
</cfif>
0
DotSPFCommented:
I find a useful solution is defining the text like so:

<cfif condition>
    <cfset inputtext = "required=yes">
<cfelse>
    <cfset inputtext = "">
</cfif>

Then include the inputtext variable inside the cfinput tag.
0
Michael_OAuthor Commented:
Hello danrosenthal,

I think your answer is the best one. Thank you for you participation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.