Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Are Those Pesky Values Passed?

Status
Not open for further replies.

skenj

Programmer
May 10, 2001
1
CA
Alright, I'm a newbie to CF but I have experience in PHP, Perl, blah blah blah. Just learning a new language for the heck of it. So here's my question:
I imagine in CF that when you submit information from a form to a script that the information is passed to the script in an array (ie, the values are stored in an array, and the array is being passed in to the script).

Well, I have a form that dynamically generates a list of students. What I want to do be able to do is click on a checkbox next to a students name to delete that student. However, I want to be able to do this with multiple students at the same time. And finally, here's the big problem: how do I know how many students were checked? If the values are being passed in an array I could just get the lenght of the array and dynamically generate my SQL command by looping through the array.

Is there a way for me to reference this array, or does it even exist, or am I WAY out in left field here?

Any help would be appreciated.

Thanks y'all.... glad I found this site... lot'o'stuff here.
 
Hey Skenj,

CF doesn't pass the form variables in via an array (at least that I'm aware of), you just access them as "#form.varName# or just "#varName#" if there are no local variables with the same name. What I suggest in cases like you're describing is to create the form variables with a similar naming convention such as student1,student2,student3, etc.. and then create a hidden variable which holds the number of student variables being submitted.

On the action page, just create a loop that checks for the existance of each variable and processes it if it exists. You will use the hidden count variable to know how many to look for.

<cfloop from=&quot;1&quot; to=#form.CountVar# index=&quot;x&quot;>

<cfset delList = &quot;&quot;>
<cfif isdefined(&quot;form.student#x#&quot;)>
<cfset delList = listappend(delList,evaluate(&quot;form.student#x#&quot;))>
</cfif>

</cfloop>

You can then just do a delete query like 'delete from studentTable where primKey in (#delList#)'.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top