Results 1 to 2 of 2

Thread: Arrays in a Form

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Seattle Area

    Arrays in a Form

    How do I get a CF Form to pass an array variable?

    For this example script I want the data to list at the top and pass back to prefill the fields as well if you hit submit. This passes the basic variable just fine, but not the array. So what is the proper method for passing an array through a form?

    <!---one string variable, one array --->
    <cfif Not IsDefined ("Form.nameF")>
    	<cfset Form.nameF="">
    <cfif Not IsDefined ("Form.address")>
    	<cfset form.address=ArrayNew(1)>
    	<cfset form.address[1]="">
    	<cfset form.address[2]="">
    	<cfset form.address[3]="">
    <!---form to take in new variable and array values--->
    <cfoutput>Previous Entry<br>
    <cfloop from="1" to="3" index="i">
        Address #i#: #address[i]#<br>
    <cfform name="basic" method="post">
        First Name: <cfinput name="nameF" value="#Form.nameF#" type="text" size="30"><br />  
        <cfloop from="1" to="3" index="i">
        	Address <cfoutput>#i#: </cfoutput><cfinput name="address[i]" value="#form.address[i]#" type="text" size="30"><br />
    	<cfinput name="submit" type="submit" value="Submit">

  2. #2
    Join Date
    Feb 2006
    Array is an complex object where form field is simple value so you can not pass array through form, only form fields. What you can do i scalar Array into forms fileds, which means grab whatever is in array and create form fields from it just like your example does with address. One that form is sibmited it will pass that info as form fields where you can do whatever with data even recreate an array again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center