• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 524
  • Last Modified:

cfinput tag problem

Hi!  I need to insert a loop, textfields and checkboxs, into database.  After I submit the form, I get this error message:

Attribute validation error for tag CFINPUT.
The value of the attribute TYPE, which is currently "text1", must be one of the values: RADIO,CHECKBOX,PASSWORD,TEXT.
 
The Error Occurred in C:\CFusionMX\wwwroot\CS1530 Project\create_exam.cfm: line 109

107 :   <!--- use a counter as shown below, the counter becomes part of the variable name
108 :   so you will have text1, text2, etc... --->
109 :   <td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>

Notice: I only get error about type="text#counter#", but not an error for type="checkbox#counter#."  Please let me know what cause this error.
------------------------------------------------------------------------------------------------------
<cfloop index=counter from="1" to="10" step="1">
<tr>
  <td>#counter#.</td>
  <!--- use a counter as shown below, the counter becomes part of the variable name
  so you will have text1, text2, etc... --->
  <td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>
  <td><cfinput type="checkbox#counter#" name="correct" value=""><br></td>
<!--- <td><input type="checkbox" name="correct" value="No"><br></td>--->
</tr>
<cfset q_ans_id=counter>
</cfloop>

0
yrs7
Asked:
yrs7
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
James RodgersWeb Applications DeveloperCommented:
change
<td><cfinput type="text#counter#" name="ans_answer" value="" size=120></td>

to
<td><cfinput type="text" name="ans_answer#counter#" value="" size=120></td>
0
 
James RodgersWeb Applications DeveloperCommented:
also
if you are looking for a yes/no answer you should use radio buttons instead of checkboxes, you can select both options in a checkbox situation but you can only check one radio button option in a group

<td><cfinput type="radio" name="radAnswer#counter#" value="yes"></td>
<td><cfinput type="radio" name="radAnswer#counter#" value="no"></td>
0
 
hartCommented:
yes jesters right

the type should be text,radio,checkbox etc...
u can't change that. u always change the name attribute..

Regards
Hart
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mrichmonCommented:
You are trying to dynamically change the type of the inputs.  This is incorrect.  I think what you want to do is dynamically create the names of the inputs.

The reason that you only get an error for the text type is because it stops processing the page after the first error.  If you fix that one then it will again die on the second error.

So when you  dynamically create inputs you should do it like this :

<input type="checkbox" name="checkbox#counter#">
or like this :
<input type="text" name="text#counter#">

THese of course need to be within a cfoutput so that the #counter# will be evaluated.

Then on the procesing page you can access them like this :

<cfset currenttext = Form["text" & counter]>
or
<cfset currenttext = Evaluate("Form.text#counter#")>
0
 
yrs7Author Commented:
Thanks for all experts help!  I have one question for mrichmon.... do I need to put <cfset currenttext = Form["text" & counter]> in a loop to insert the 10 textfields and checkboxes into database?
Sicnerely
0
 
hartCommented:
no just use Evaluate("Form.text#counter#"), it will work fine.

but for radio buttons and checkboxes u will have to see wether its defined or not

i.e
<cfif isdefined("form.text#counter#")>
#Evaluate("Form.text#counter#")#
</cfif>

Regards
Hart
0
 
mrichmonCommented:
Yes you need to put it in a loop that increments the counter or you can manually increment the counter

Like this :

<cfloop index="counter" from="1" to = "#numfields#>
<cfset currenttext = Form["text" & counter]>
</cfloop>

And you can do whatever else you want in the loop.

The Evaluate("Form.text#counter#") does the same thing - it is just an older syntax and personally I like the newer syntax better because it is cleaner to write - and actually works in some situations where the Evaluate syntax doesn't (as your dynamically generated pages get more complex - for example allowing the user to dynamically add and remove rows from your forms)
0
 
yrs7Author Commented:
Hello!  I got a problem in a part which is executed before the code posted above.  I will get back to you after I fix that part of problem.  
Best Regard
Ying
0
 
hartCommented:
mrichmon : "and actually works in some situations where the Evaluate syntax doesn't ????"

buddy i have been using this for very long time and with many complicated loops and variables, but i have never come across any hassleswith evaluate...

Regards
Hart
0
 
mrichmonCommented:
Well, I too felt the same way - I had been usin gthe evaluate syntax only and it always seemed to work... and then boom - I write an even more complex program and now it no longer works.  It would be too off topic to post the entire thing here - but if Evaluate works for all of your situations then you can stick with that.  Me? - I and the other programmers that I correspond with on other forums have all decided to move to the other syntax as we have come accross these situations.

At least keep the alternate syntax in mind in case you do ever come accross one of these cases...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now