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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request.Form Vars - need help!

Status
Not open for further replies.

CharlieMike73

Programmer
May 17, 2002
120
US
Hi I have a form that submits to itself.

What I want to know is, is there a simple way to get all the data that is submitted in the form in one line and use the same name for the variables as the control names in the form?

example:

submitted = Request.Form("submitted")
unit_id = Request.Form("unit_id")
activity = Request.Form("activity")
eamsa = Request.Form("eamsa")


Is there some way to get all these and the rest that are on the form with one line of code or at least a few lines without explicitly requesting each entry?

Regs,
Charlie
 
probably not.

there might be some collection you can loop, but I think that might be error prone or be more trouble than it is worth.

Let me guess and say you are really just trying to make you page more readable or shorter? Maybe look at using include files to hide some code.

Kris
- Build a system that even a fool can use, and only a fool will use it.
 
Thnx, guess I will just have to add them all one by one on the page then.

Forgive my lack of understanding, I am new to ASP, or rather I have done very little in the 6 months or so since I made my first ASP page.

Thank you!
 
You can't create variables on the fly but what you could do is use an array to keep track of the control name / value.

Loop through the request collection storing the values needed.
Code:
<html>
<body>
<%
dim aArray()
dim item
dim i
dim bFirstTime

bFirstTime = true
'Only process if data is passed in
if len(trim(&quot;&quot; & Request.Form(&quot;input1&quot;))) > 0 then
	redim aArray(1,0)
	'Loop through the form collection
	for each item in request.form
	'If this is the first time through, do not redim the array
	 if bFirstTime then
		aArray(0,0) = item
		aArray(1,0) = Request.Form(item)
		bFirstTime = false
	 else
		'Add a row to the array keeping previous information
		redim preserve aArray(1, ubound(aArray,2) + 1)
		aArray(0,ubound(aArray,2)) = item
		aArray(1,ubound(aArray,2)) = Request.Form(item)
	 end if
	next
	'Print out the array
	for i = 0 to ubound(aArray,2)
		Response.Write &quot;Control: &quot; & aArray(0, i) & &quot; | &quot;
		Response.Write &quot;Value: &quot; & aArray(1, i) & &quot;<BR>&quot;
	next
end if

%>
<hr>
<form name=testing method=post action=testgabe.asp>
	<input type=text name=input1>
	<br>
	<input type=text name=input2>
	<br>
	<input type=submit>
</form>
</body>
</html>

Hope this helps,

Gabe
 
Nice one, thats sweet - gave it a test and now I do not need to worry about if I add additional controls and forget to add them to the Request.Form (???).

Thanks to both of you I have learned something today!

Regards,
Charlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top