Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Iterating through the Request.Form Collection

Posted on 2009-04-06
7
Medium Priority
?
497 Views
Last Modified: 2012-05-06
I'm iterating through a collection of Request.Form fields and sending the data by email which works fine.
But i'm wondering if I can prevent some info from being sent.

A session variable that belongs to the cms is posted and also the data for the submit button.  

' Loop through the session collection.
  For Each objFIELD in Session.Contents
    strBody = strBody & "<p>" & objFIELD & " = "
    strBody = strBody & Session(objFIELD) & "</p>" & vbCrLf
  Next
 
The result returns like this:
 
xpage = (I don't wan't this to be sent)
Name = John
Tel = 5554433
Submit=Submit (and I don't wan't this to be sent)

Open in new window

0
Comment
Question by:GDB08
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24083355
>>But i'm wondering if I can prevent some info from being sent.

So, you can define a list (an array, etc), so that whenever the Session Key matched the array item, it will not included in the email content, like:
<%
 
myArray = array("a", "b", "c")
 
Session("a") = "1142"
Session("av") = "1fsa142"
Session("sa") = "fdhfh1142"
Session("c") = "cc  ssss"
Session("fsfsa") = "saa 1142"
 
  For Each objFIELD in Session.Contents
  	isfound = false
  	for i = 0 to Ubound(myArray)
		if myArray(i) = objFIELD then
			isfound = true
			exit for
		end if
	next
	if isfound = false then
	    strBody = strBody & "<p>" & objFIELD & " = "
    	strBody = strBody & Session(objFIELD) & "</p>" & vbCrLf
	end if
  Next
  
 response.write strBody
  
  
%>

Open in new window

0
 
LVL 28

Expert Comment

by:sybe
ID: 24084200


<%
For each field In Request.Form
    If field <> "do_not_include_this" Then
        ' include field and value in the message
    End If
Next
 
For each field In Session.Contents
    If field <> "do_not_include_this" Then
        ' include field and value in the message
    End If
Next
%>

Open in new window

0
 

Author Comment

by:GDB08
ID: 24084796
Thanks for the reply.
I've tested both soultations and can't get them to work.
Were would you add xpage and submit in the code to prevent it from be added in the email?
Best regards.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24084875
xpage is a variable name, we need to know what values you wish to prevent it from be added into the email.

or you can create a "wish" list, like:

<%

myWishArray = array("Name", "Tel")

for each i in Request.form

isfound = false
        for i = 0 to Ubound(myWishArray)
                if myWishArray(i) = i then
                        isfound = true
                        exit for
                end if
        next
        if isfound = false then
            strBody = strBody & "<p>" & i & " = "
        strBody = strBody & Request(i) & "</p>" & vbCrLf
        end if


                  next

response.write strBody

%>
0
 

Author Comment

by:GDB08
ID: 24084992
Ok, the thing is that this form processor loops through form without knowing the name of the fields.  People can create any form from cms editor and the result's are sent by email.  Therefore I can not declare the fields I wan't to be sent.  I only know that the variable xpage comes from the cms and is empty and I would not include that in the email.
xpage =
Also the submit filed is emailed
submit = submit
and I would like to get rid of that in the email.
Any other filed are not known by name and may be sent.
0
 
LVL 28

Expert Comment

by:sybe
ID: 24085026
> I've tested both soultations and can't get them to work.

I hoped thhat you would understand that you could substitute "do_not_include_this" with any fieldname you do not want to include. If you have a range of formfields which you do not want to include, you can create an array of them (as ryancys shows), or you could have multiple "If" (which is a pain) or you could do a SELECT CASE statement.


<%
For each field In Request.Form
    Select Case field
        CASE "do_not_include", "submit", "xpage"
            ' skip this, do nothing
 
        CASE Else
           ' code to include name & value 
    End Select
Next
%>

Open in new window

0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 24085095
then try this...

<%

NOTmyWishArray = array("xpage", "Submit")

for each i in Request.form

isfound = false
        for j = 0 to Ubound(NOTmyWishArray)
                if lcase(NOTmyWishArray(j)) = lcase(i) then
                        isfound = true
                        exit for
                end if
        next
        if isfound = false then
            strBody = strBody & "<p>" & i & " = "
        strBody = strBody & Request(i) & "</p>" & vbCrLf
        end if


                  next

response.write strBody

%>




the previous one should be as: (previous one got some problem, use this instead)

<%

myWishArray = array("Name", "Tel")

for each i in Request.form

isfound = false
        for j = 0 to Ubound(myWishArray)
                if lcase(myWishArray(j)) = lcase(i) then
                        isfound = true
                        exit for
                end if
        next
        if isfound = true then
            strBody = strBody & "<p>" & i & " = "
        strBody = strBody & Request(i) & "</p>" & vbCrLf
        end if


                  next

response.write strBody

%>
0

Featured Post

[Webinar] Protection from Cyberattacks

In this session, we’ll dive into the complexities of modern cyber threats and why only multi-vector protection can keep today’s businesses secure through the various stages of a cyberattack, across multiple vectors. Thursday September 14, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question