Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Best way to pass unknown number of variables
Old 11-14-2005, 10:14 PM Best way to pass unknown number of variables
Novice Talker

Posts: 13
Trades: 0
I have created a form that will have 30 checkboxes. The user can select between 1 and 30 of these checkboxes. Once they have done this, I want to submit the values of the selected checkboxes to another page that analyzes the boxes that were checked. I understand that I could set up 30 URL variables but I dont think that this is best practice. What is the best way for me to do this? Write the variables to a file or XML? I am not very adept at either but if someone could point me in the right direction, that would be great. Thanks!!!
kyle_davis13 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-15-2005, 10:01 AM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
When you create the form and it is submitted, all the data will be passed to the next page. You just need to use a scripting language to interpret the data.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-15-2005, 10:08 AM
Novice Talker

Posts: 13
Trades: 0
yes, but what scripting language can I use to pass variables without having to use URL variables?
kyle_davis13 is offline
Reply With Quote
View Public Profile
 
Old 11-15-2005, 10:13 AM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
You don't need any language to pass the variables. The normal POST function of a form does that for you. You would need a language either PHP, ASP, or another server side language. Simple example - If you submit a form with an input called "asd" using post:

Code:
<form action="nextpage.asp" method="post">
     <input type="text" name="asd"><input type="submit">
</form>
you can call write the data to the page like this:

ASP:
<% Response.Write Request.Form("asd") %>

PHP:
<?php echo $_POST["asd"]?>

Keep in mind this data is for one-time use. To store the data you'd use a database of some sort.

Form Basics:
http://webmonkey.wired.com/webmonkey...l?tw=authoring
http://webmonkey.wired.com/webmonkey...tw=programming
http://webmonkey.wired.com/webmonkey...tw=programming

Last edited by funkdaddu; 11-15-2005 at 10:24 AM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-15-2005, 10:16 AM
Novice Talker

Posts: 13
Trades: 0
ok. The problem is that I dont know how many variables are going to be passed. the results of the form selections will be going into my SQL statement on the action page. so how do I set up that SQL statement when I am unsure of how many variables are going to be passed?
kyle_davis13 is offline
Reply With Quote
View Public Profile
 
Old 11-15-2005, 10:30 AM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
It doesn't matter, really. You can use a loop function to create an SQL string for any/all form data that is passed. Would you be using ASP or PHP for this? If you give an example of you code I can help out.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-15-2005, 11:35 AM
Novice Talker

Posts: 13
Trades: 0
I would be using ASP. Basically, the form consists of a list of pictures. If the user likes the pictures they click the checkbox next to it. Once they have gone through all of the pictures and click submit, I want to show them a list of similar pictures that they may like. So the SQL would be something like

select *
froM similarPictures
Where similar_picture_id = 'some random number of variables
kyle_davis13 is offline
Reply With Quote
View Public Profile
 
Old 11-15-2005, 02:56 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Form page:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
	</head>

	<body bgcolor="#ffffff">
		<form id="FormName" action="form.asp" method="post" name="FormName">
			<p><input type="checkbox" name="Picture" value="1"><img src="(EmptyReference!)" alt="" height="32" width="32" border="0"></p>
			<p><input type="checkbox" name="Picture" value="2"><img src="(EmptyReference!)" alt="" height="32" width="32" border="0"></p>
			<p><input type="checkbox" name="Picture" value="3"><img src="(EmptyReference!)" alt="" height="32" width="32" border="0"></p>
			<p><input type="submit" name="submitButtonName"></p>
		</form>
	</body>

</html>
asp code in "form.asp":
Code:
<%
pix = Request.Form("Picture") 'gets all the pictures checked like this: CheckBoxValue1, CheckBoxValue2, CheckBoxValue3 etc...
pix = pix 'format this how you're going to get them from your DB - I don't know how you're doing it
sql = "SELECT * FROM similarPictures WHERE similar_picture_id = " & pix
Response.Write sql 'writing out the sql to show
%>
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-15-2005, 03:17 PM
Novice Talker

Posts: 13
Trades: 0
wow! thanks a lot. I really expreciate your help!!!
kyle_davis13 is offline
Reply With Quote
View Public Profile
 
Old 11-15-2005, 03:41 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
as checkboxes only return their value when checked, the simple way is to name all checkboxes the same and the values will then be returned as a single comma seperated value string.
This can then be split into array using
Code:
dim img_name_array
img_id_array = split(request.form("chkbox_name"),",")
You can then build your SQL string with
Code:
SQLColumn = " similar_picture_id = "
strSQL = "select fieldlist from similarPictures where "
dim i
for i = 0 to ubound(img_id_array)
if i <> ubound(img_id_array) then
     strSQL = strSQL & SQLColumn & cint(img_id_array(i)) & " OR "
else 
     strSQL = strSQL & SQLColumn & cint(img_id_array(i)) 
end if
next
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-15-2005, 03:52 PM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
See that's what happens when the phone rings while writing a reply

and funkdaddu's answer would have a problem if more than one box was checked because of the commas.
If that were the case you would need to use
Code:
 
similar_picture_id IN " & pix
and some SQL servers would throw an error if similar_picture_id is a numeric value because POST values are returned as a string.



BTW can someone move this to ASP ?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-15-2005, 04:07 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Yeah, I'm not an SQL whiz, so that fills in my blanks. I didn't know if he was going to just choose them by id or name or what.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-15-2005, 05:44 PM
Novice Talker

Posts: 13
Trades: 0
I keep gettting the error that the element bandname is not defined in bandform.

Here is my code:

Code:
<table border="1">
    <tr>

        <form id="bandform" action="testaction.cfm" method="post" name="bandform">
<cfloop from="1" to="#showNum#" index="i">
    <tr>
            <td>
            <cfoutput>
                <p><input type="checkbox" name="bandname" value="#getItems.bands_id[ListGetAt(randomItems, i)]#" id="picture">#getItems.bands_name[ListGetAt(randomItems, i)]#</p>
            </cfoutput>
            </td>
    </tr>
 </cfloop>

             <p><input type="submit" name="submitButtonName"></p>

        </form>

    </tr>
    </table>

</cfif>
The above code gets me a random list of ten band id's (picture id's). Then when I try and review the results on the testaction.cfm I get the error that BANDNAME is not an element of BANDFORM. I dont understand what I am doing wrong. Here is my code on the action page:

Code:
<cfoutput>
    #bandform.bandname#
</cfoutput>
i JUST WANT TO SEE the results of the variables. What the ID was of the pictures that the user selected on the screen. Why am I getting it wrong?

Last edited by kyle_davis13; 11-15-2005 at 06:02 PM..
kyle_davis13 is offline
Reply With Quote
View Public Profile
 
Old 11-15-2005, 09:36 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
Hmmmm... I thought you were using ASP... I can't help with cold fusion, sorry.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 11-16-2005, 05:58 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Same here

You could try the Tek-Tips Coldfusion forum.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Best way to pass unknown number of variables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.07566 seconds with 12 queries