HTML Input Forms – Sending in a List to ColdFusion

HTML + ColdFusion Lists

This post is a continuation of a previous article I wrote about sending in an array through HTML to your php script. This article deals with doing a similar thing except using ColdFusion. If you are new to the subject, it is highly recommended that you read the first article.

Though newer versions of ColdFusion offer support for arrays, earlier versions were centered instead around using lists. Because of this fact, this example will detail how to send a list into ColdFusion then loop over that list, allowing you you to perform whatever actions you need to do in your HTML form.

The Code

<form method="post" action="">
  <p>Enter your friend's names (first, last):</p>
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input maxlength="30" name="friend" size="30" type="text" />
  <input type="submit" value="Submit" />

</form>

<cfif isDefined("Form.friend")>
  <cfloop index="ListElement" list=#Form.friend#>
     <cfoutput>#ListElement#</cfoutput>
     <!--- Do something with this value --->
     </cfloop>
  </cfif>
 

How It Works

Because all of the <input> elements in the form have the same “name” value, your ColdFusion server will create a list variable called #Form.name# that you will be able to loop through and perform actions on each of the elements.

A handy feature of ColdFusion is that when it creates the list it doesn’t matter if your user enters data only in one of the boxes or only the last one. The list is put together for you of valid inputs from the user. Using this method, you don’t need to check to make sure the value isn’t blank!

Have fun!

How To Setup A Local ColdFusion Development Environment in Windows

Interested in programming in the ColdFusion language?

Setting up a ColdFusion development environment on your local computer is easy! Just follow these simple steps. This small walkthrough will enable you to develop and execute ColdFusion web applications on your Windows PC. This software is not intended for commercial use — for that, you’ll need a licensed copy.

1. Download ColdFusion Developer Edition (for free!)

You may need to sign into your Adobe.com account (or create one if you haven’t got one yet) in order to download the Developer Edition of the ColdFusion server.

Download ColdFusion Developer Edition from Adobe.com.

2. Installation Options

After downloading the software, begin installation. For all installation screens you should select all default options except in the screens shown in the images below. These settings will allow you to have the ColdFusion app server run on your computer locally.

Screen 1: Skip Product Key by selecting “Developer Edition”

Screen 2: Select “Server configuration”

Step 3:Select “Built-in web server” (This one is really important!)

3. Finish Installation

Once ColdFusion is finished, it will launch the completion script in your web browser and finish the installation. After that is complete, you will be taken to the ColdFusion Administrator screen, which will allow you to change all of your ColdFusion server settings and looks like this:

In the future you may need to change ColdFusion settings on your computer. This is the panel you will use to make those changes.

If you installed ColdFusion correctly, clicking here will take you to your ColdFusion Administrator.

Happy programming!