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

Looping through form fields

Status
Not open for further replies.

peterswan

Programmer
Sep 25, 2002
263
US
Hello,

I'm looping through all form fields on a page and getting them to display as hidden fields on the next page. Here's the code I'm using:

For each item in Upload.Form
Response.Write &quot;<input type=hidden name=&quot; & &quot;&quot;&quot;&quot; & Item.name & &quot;&quot;&quot;&quot; & &quot; value=&quot; & &quot;&quot;&quot;&quot; & item & &quot;&quot;&quot;&quot; & &quot;>&quot; & vbNewLine
Next

The reason why I'm using Upload.Form insead of Request.Form is because I'm using an upload component on the previous page. This works fine except it won't display the hidden fields in the same order as they were on the previous page. Is there any way to arrange them in their original order, even though I'm using Upload.Form?

Thanks for any help,

Peter Swanson
 
Hi Snowboarder,

Thanks for your response.

After I upload the file to the server and gather all the values from the form fields, I'll send it to a confirmation page that prints the details of the copy request. If &quot;Name&quot;, &quot;Phone&quot;, and &quot;Email&quot; are all jumbled up in between &quot;# of copies&quot; &quot;Time Due&quot;, &quot;# of originals&quot;, &quot;Paper Color&quot;, etc., the confirmation page and confirmation emails look funny.

I'd like to retain the original order of the fields. It looks a lot nicer.

I found some code on a website that explained how to do this with request.form, but not with upload.form.

Any ideas?

Thanks,

Peter Swanson
 

Well this part isn't seen by the user.. so you don't even really need vbNewLine...

Code:
Response.Write &quot;<input type=hidden name=&quot; & &quot;&quot;&quot;&quot; & Item.name & &quot;&quot;&quot;&quot; & &quot; value=&quot; & &quot;&quot;&quot;&quot; & item & &quot;&quot;&quot;&quot; & &quot;>&quot;

I still don't understand why they would be out of order, you would display it how you want on the page by response.writeing each hidden value where you want on the page..

Response.Write(Request.Form(&quot;some_item.name&quot;))

etc..

www.vzio.com
ASP WEB DEVELOPMENT



 
Hi Snowboarder,

Thanks for your response.

Two things come to mind. First, remember, I have no idea what the names of the fields are, since they're chosen by someone else (I had forgotten to mention this). This means I can't tell the page to put this one first and this one next, etc.

Second, I've got the code to put everything in order if I use Request.form. Here's the web page that explains it:


Secondly, I need to use Upload.form because of an upload element on the page before.

I know this is a tough question. Thanks to anyone who even has a hunch.

Cheers,

Peter Swanson
 
I agree with onpnt that I can't see why they need to be in order. Generally your lucky if they come through in order in the first place, the more fields, the more luck it takes. The fields are stored as part of a hash table and the more entries you use the less of a chance you will have of retrieving them in the same order as they were written in the original web page. If your simply going to be passing them on asgain to the next page you should not need to retain the original order fo the fields. In fact, you should not rely on those fields staying in the same order.
Perhaps if you outline the problem a little more genarlly we can help you come up with a better idea or see something you missed.
-Tarwn &quot;The problem with a kludge is eventually you're going to have to back and do it right.&quot; - Programmers Saying (The Wiz Biz - Rick Cook)
&quot;Your a geek!&quot; - My Girlfriends saying
 
Or in your loop of hidden values.. keep track of each name in a string..
Code:
All_names = All_names & Item.name & space(1)

All_names = trim(All_names)

Response.Write &quot;<input type=hidden name=&quot; & &quot;&quot;&quot;&quot; & &quot;allvalues&quot; & &quot;&quot;&quot;&quot; & &quot; value=&quot; & &quot;&quot;&quot;&quot; & All_names & &quot;&quot;&quot;&quot; & &quot;>&quot;

Then you can split them on the next page.. then go through them with a for each loop..

www.vzio.com
ASP WEB DEVELOPMENT



 
Hi guys,

Thanks for answering. I think Snowboarder's answer will work. I'll insert into the database from the loop since order isn't important for the inserts. But the confirmation information will come from names that are passed on as a string that are later split into a loop to get their values. The order will be retained because the order of the string won't change when I bring it across.

Thanks for your help,

Peter Swanson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top