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!

Query results in form, passing to action page

Status
Not open for further replies.

promoguy

MIS
Oct 4, 2000
4
US
I have coded a nice CF site, and have been able to do a lot of queries and updates. But this one, while so simple, I can't do.

I am really needing to see some examples or get some help.

I am pulling a list of units from a database. Putting them in a table within a form.

Each form field needs a unique name, and the number of records in the database can vary. The user is to check the box of the unit they want, and enter a quantity. The form will send that and the unit name and price to the action page. But I got stuck on the unique field names.

Then on the action page, the order will be simply sent in an e-mail, so I need to output the items selected. Not knowing the fieldnames, I get stuck here too.


Here is my Form code:

I have not written the action page yet.

<CFform
action=&quot;form_handler.cfm&quot;
method=&quot;POST&quot;
name=&quot;Form&quot;>
<div align=&quot;center&quot;>
<center>
<table border=&quot;0&quot; width=&quot;85%&quot;>
<tr>
<td width=&quot;75&quot; align=&quot;center&quot; bgcolor=&quot;#800000&quot;><font color=&quot;#FFFFCC&quot;><b>Unit</b></font></td>
<td width=&quot;33%&quot; align=&quot;center&quot; bgcolor=&quot;#800000&quot;><font color=&quot;#FFFFCC&quot;><b>Quantity
Available</b></font></td>
<td width=&quot;34%&quot; align=&quot;center&quot; bgcolor=&quot;#800000&quot;><font color=&quot;#FFFFCC&quot;><b>Price</b></font></td>
<td width=&quot;34%&quot; align=&quot;center&quot; bgcolor=&quot;#800000&quot;><font color=&quot;#FFFFCC&quot;><b>Quantity
Needed</b></font></td>
<td width=&quot;34%&quot; align=&quot;center&quot; bgcolor=&quot;#800000&quot;><font color=&quot;#FFFFCC&quot;><b>Check
Box</b></font></td>
</tr>
<CFOUTPUT QUERY = &quot;Annex1&quot;>

<tr>
<td width=&quot;75%&quot; bgcolor=&quot;##FFFFCC&quot;>#unit#</td>
<input type=&quot;hidden&quot; name=&quot;Unit&quot; &quot; Value = &quot;#unit#&quot;>
<td width=&quot;33%&quot; bgcolor=&quot;##FFFFCC&quot;>#quantity#</td>
<td width=&quot;34%&quot; bgcolor=&quot;##FFFFCC&quot;>#price#</td>
<input type=&quot;hidden&quot; name=&quot;Price&quot; &quot; Value = &quot;#price#&quot;>
<td width=&quot;34%&quot; bgcolor=&quot;##FFFFCC&quot;>
<p align=&quot;center&quot;><input type=&quot;text&quot; name=&quot;quant&quot; size=&quot;10&quot; Value = &quot;&quot;></td>
<td width=&quot;34%&quot; bgcolor=&quot;##FFFFCC&quot;>
<p align=&quot;center&quot;><input type=&quot;checkbox&quot; name=&quot;selected&quot; value=&quot;OFF&quot;></td>
</tr>

</CFOUTPUT>

</table>
<!--Hidden Stuff-->
<CFOUTPUT Query = &quot;UserInfo&quot;>
<input type=&quot;hidden&quot; name=&quot;Email&quot; Value = &quot;#Email#&quot;>

</font>

<tr>
<td width=&quot;29%&quot;>
<p align=&quot;left&quot;><b><font color=&quot;##800000&quot;>Your Name:</font></</td></b>
<td width=&quot;71%&quot;><input type=&quot;text&quot; name=&quot;sentby&quot; Value = &quot;#FirstName# #LastName#&quot; size=&quot;50&quot;></td>
</tr>
<font face=&quot;Tahoma, Century Gothic, Avant Garde, Arial, Helvetica&quot;>
<!--End Hidden Stuff-->
</cfoutput>
</center>
</div>
<p align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></p>
</CFform>



 
Hi,

this might help. When I need a list of unique form variables I do this:
<FORM name=&quot;form&quot;
action=&quot;doit.cfm&quot;
method=&quot;post&quot;>

<CFOUTPUT query=&quot;MyQuery&quot;>


<input type=&quot;checkbox&quot;
name=&quot;selected#CurrentRow#&quot;
value=&quot;OFF&quot;>

<!--- Just add the #CurrentRow# after each variable that
is comming from the query then you will have a list
of form variables that looks like this:
selected1, selected2, selected3, selected4 ...
and so on for each form variable.
--->

</CFOUTPUT>

<input type=&quot;hidden&quot;
name=&quot;count&quot;
value=&quot;#MyQuery.recordcount#&quot;>

</form>

<!--- I go ahead and put the recordcount in as a hidden
variable just to save stress in the action page.
--->

Then in the action page you do this:

<CFLOOP Index=&quot;X&quot; From = &quot;1&quot; To =&quot;#form.count#&quot;>
<CFSET formvar=&quot;selected#X#&quot;>
<CFSET num=#Evaluate(formvar)#>

<!--- At this point Num is the value of the current row
of the form. It will step through each row. You
Can do whatever you need to in here.
--->

</CFLOOP>


Hope that does it for you.

Have fun...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top