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!

Capturing All Form Output into Single String

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I have a number of VBScript / HTML forms, each with different kinds of information. The forms already submit back to themselves, then redirect as needed depending upon which button is pressed (they have several Submit buttons). The form elements are radio buttons, checkboxes, pulldowns, textboxes so there is a variety. What I want to do is to capture each and every item (some might be text while others are numeric) and put it together as a single comma-delimited list, asigning a variable name to the resulting string. I don't care what they are individually in this case. I'm not sure how to begin - can anyone help? It should be pretty simple. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
I'm trying to do this in VBScript, which is the forum I chose, so if this is the wrong one, it would help if I knew the difference so it doesn't happen again. "ASP" is an "Application Service Provider" and I don't understand what that has to do with this question. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Nope, "Application Service Provider" is a marketroid term that came into popular use after Active Server Pages already co-opted the acronym ASP!

Be that as it may, The ASP forum here is the one that deals most directly with the use of VBScript and web servers.

You are absolutely right though, you can use VBScript client-side with a non-ASP web server. What we need is a "VBScript: DHTML" forum, but we don't. So this is the best place to come if you don't feel the ASP people can help you.

I'd be glad to help if you could simplify things for me a little.

For example, you say your forms are submitting back to themselves. I'd normally think this would mean posting form data back to the same ASP page that generated the client page containing the form. Obviously I'm way off. Could you post a small example of a page that does this, you know, stripped to essentials?

It sounds like you may want to build this comma-delimited string client side to submit it to a CGI script or something, but I don't want to go off on a tangeant if this isn't what you need.
 
Well, I'm home now and it's an office project but maybe I can give a rough example anyway off the top of my head (it might not be letter perfect but you'll get the idea) but hopefully it will make some sense.

Each page has a form with some elements of various sorts, mostly checkboxes but there are some option tags and text tags too here and there. In this example, selectchoices.asp is the name of the same script in which the form exists:

[tt]<form action=&quot;selectchoices.asp&quot; method=&quot;post&quot;>
<input type=&quot;Reset&quot; name=&quot;mode&quot; value=&quot; Reset &quot;>
<input type=&quot;submit&quot; name=&quot;mode&quot; value=&quot;Save Selections&quot;>
Select Choices
<input type=checkbox name=&quot;choice&quot; value=1>Choice 1
<input type=checkbox name=&quot;choice&quot; value=2>Choice 2
<input type=checkbox name=&quot;choice&quot; value=3>Choice 3
Enter Something
<input type=text size=25 name=someinput>
</form>[/tt]

When submitted, it does something like this, which is actually in the script above the form tags but I put it below here to show the progression. On some pages, the input tag &quot;name&quot; is different but the &quot;value&quot; is the same, which will be a problem, but I'll cross that bridge when I come to it:

[tt]<% If request(&quot;mode&quot;) = &quot;Save Selections&quot; Then
DataConn.Execute &quot;INSERT into searchchoices (choice, SessionID) &quot; &_
&quot;VALUES (&quot; & value & &quot;, &quot; & session.SessionID & &quot;)&quot;
Response.Redirect(&quot;mainsearch.asp&quot;)
End if %>[/tt]

The table writing done here gets deleted later on, and each script has it's own temp table - its contents are only there temporarily. I can't change this basic functionality (I inhereted it) but need to track usage carefully into another single table for all the pages. To do this additional logging, I'll be using some &quot;insert into&quot; lines similar to those above.

The information I need will be in the form of a single comma-delimited string to store in a table field, the purpose of which is to log what users did exactly on each page. Each form submission will add a new line to the table.

This string might look like the example below, which will tell me which check boxes were checked and what was entered in the text field. Because I will know what form they were on (I'm capturing that too), I'll know what these values mean:

[tt]1, 3, 25000[/tt]

This will give us information more detailed than what the server's log can do and, as a small non-profit, we need this detailed information for the funding. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Sure looks like ASP to me. If you're pulling my leg I'm afraid it has come off in your hand! ;-)

Ok, I have a good idea what you're asking about. What I don't understand is why you don't want to store these items as separate fields in your database table instead of a single text field with the data comma-delimited.

But you have the whole picture, not me. Maybe you have a lot of different forms with different sets of fields you need to capture. If so, you might want to consider at least storing a &quot;form type&quot; field in this table to make subsequent analysis easier.

So lets leave all that aside. Back to your question.

Is there some reason not to just concatenate the stuff into a comma-delimited string? Obviously you have the concept down, you're concatenating strings all over the place in your sample above.

For example:
Code:
<%@ Language=VBScript %>
<%
Option Explicit

Dim varElement, strDelimited

If Request.ServerVariables(&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; Then
	For Each varElement In Request.Form
		strDelimited = strDelimited & _
			&quot;, &quot; & Request.Form(varElement)
	Next
	strDelimited = Mid(strDelimited, 3)
End If
%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<FORM id=FORM1 name=FORM1 action=test.asp method=post>
<INPUT id=text1 name=text1><BR>
<INPUT id=text2 name=text2><BR>
<INPUT id=checkbox1 type=checkbox name=checkbox1>Check me<BR>
<INPUT id=submit1 type=submit value=Submit name=submit1>
</FORM><BR>
<%=strDelimited%>
</BODY>
</HTML>
This example points out one pitfall you need to be aware of though: a checkbox form element sends nothing if the box is unchecked - this is how they work.

Give the example above a try.

If you fill in text1 with &quot;hello&quot; and text2 with &quot;world&quot; and check checkbox1, and then click submit1 you will get back:
Code:
hello, world, on, Submit
The default value for a checkbox is &quot;on&quot;. If you don't check the checkbox though, it won't show up at the server at all, giving:
Code:
hello, world, Submit
Even a blank (empty) textbox will return an empty string though:
Code:
, , Submit
So you can see that there are some limitations you may need to code around if you want to capture &quot;unchecked&quot; checkboxes.

Does this help?
 
I'm afraid I still do not understand your references to ASP. You say right at the top of your example: &quot;Language=VBScript&quot; - is this not the VBScript Forum? That's what it says at the top of my screen and VBScript is what I thought I was writing! I'm quite confused about this.

Thanks for the snippet. I'll try it at the office on Monday. I didn't realize that checkboxes would provide only &quot;on&quot; but I did realize that unchecked boxes would supply nothing. Can I not submit some kind of value with a checkbox that is checked, such as the &quot;name&quot; part of the tag if it's checked? If not, I can probably still figure out which is checked by the position in the string.

The individual pieces of data are already being processed by other parts of the scripts. The purpose of what I am trying to do here is simply for logging what is checked and if I were to do each one in a separate field in the database table, I would end up with many dozens of fields. This is an add-on to scripts that already exist so rewriting them from scratch is not an option either.

Don Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top