Search code examples
coldfusioncoldfusion-9

Pass Text and Inputs Without Specifying Each as a Variable


I have the following form on form.html, a regular html page.

<form action="confirmation.cfm" name="myform">

What is 1+1<br>
<input type="text" value=""><br><br>

What is 2+2<br>
<input type="text" value=""><br><br>

What is 3+3<br>
<input type="text" value=""><br><br>

<input type="submit">

</form>

When this form is submitted, I want all of the questions and the text put in the associated input boxes to be submitted to a ColdFusion page and just displayed. Without having to specify the variable name for each question and each input, is there a way I can pass this information, maybe by just using the form name, myform?

In otherwords, if a user put in the answers to each of the questions, 2, 4, 6 and submitted the form on form.html, I'd like confirmation.cfm, to display the following:

What is 1+1
2

What is 2+2
4

What is 3+3
6

How can I do this?


Solution

  • You can use form scope. FORM scope at as structure and you can easily loop through it. May be below code will help.

    <cfloop collection="#form#" item="lc">
        <cfoutput>#form[lc]#<br/></cfoutput>
    </cfloop>