Solved

cfinput tag problem

Posted on 2003-11-18
13
513 Views
Last Modified: 2013-12-24
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
Comment
Question by:yrs7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
13 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 25 total points
ID: 9775164
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
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9775191
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
 
LVL 11

Expert Comment

by:hart
ID: 9776430
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
Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

 
LVL 35

Expert Comment

by:mrichmon
ID: 9781016
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
 

Author Comment

by:yrs7
ID: 9786067
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
 
LVL 11

Expert Comment

by:hart
ID: 9786110
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
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 25 total points
ID: 9788547
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
 

Author Comment

by:yrs7
ID: 9790614
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
 
LVL 11

Expert Comment

by:hart
ID: 9794728
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
 
LVL 35

Expert Comment

by:mrichmon
ID: 9811756
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question