Forums

ASP

This topic is locked

Matt's Email Newsletter - Request.Form Problem

Posted 07 Dec 2004 17:58:57
1
has voted
07 Dec 2004 17:58:57 Jim Moore posted:
When I use the bindings panel to bind two request variables (name and email) on my newsletter confirm page, using Bindings>+Request VAriables and the Request.Form option and drage them onto my confirm page, e.g., Thank you for signing up for our newsletter, {Form.name}, to create a more personal message the varables are not displayed when the Signup page is loaded. If I use GET instead of POST on my form used to input the name and email, the dynamic data is displayed, but the name and email is not insereted in my database table. Is there a way to have the name and email inserted in the tabl AND also have them inserted in the text as dynamic data to display the form name and email?
Jim

Replies

Replied 08 Dec 2004 11:20:00
08 Dec 2004 11:20:00 Lee Diggins replied:
Hi Jim

Have you changed your insert statement to use request.querystring variables? Can you post the code for the signup, insert and confirm pages.



Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 08 Dec 2004 18:26:05
08 Dec 2004 18:26:05 Jim Moore replied:
Lee,
Here is my signup, insert and confirm code:

'***SIGNUP, INSERT AND REQUEST.FORM CODE:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/connSubscribers.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert") = "form1" Then

MM_editConnection = MM_connSubscribers_STRING
MM_editTable = "Subscribers"
MM_editRedirectUrl = "confirm-signup.asp"
MM_fieldsStr = "Name|value|Email|value"
MM_columnsStr = "Name|',none,''|Email|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert") <> "" Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),","
MM_delim = MM_typeArray(0)
If (MM_delim = "none" Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none" Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none" Then MM_emptyVal = ""
If (MM_formVal = "" Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "" Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'" Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''" & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & " values (" & MM_dbValues & ""

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_connSubscribers_STRING
Recordset1.Source = "SELECT * FROM Subscribers"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>


'***SIGNUP FORM CODE:
<form name="form1" method="POST" action="<%=MM_editAction%>">
<table width="244" border="1" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="95"><font face="Arial, Helvetica, sans-serif">Name:</font></td>
<td width="149"> <font face="Arial, Helvetica, sans-serif">
<input name="Name" type="text" id="Name2">
</font></td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif">E-mail:</font></td>
<td> <font face="Arial, Helvetica, sans-serif">
<input name="Email" type="text" id="Email">
</font></td>
</tr>
<tr>
<td> <font face="Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Sign me up:">
</font></td>
<td><font face="Arial, Helvetica, sans-serif"> </font></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>

'***CONFIRM PAGE CODE:

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../Connections/connSubscribers.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_connSubscribers_STRING
Recordset1.Source = "SELECT * FROM Subscribers"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Panama City Beach Now eNews Signup</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Provides nformation on hotels, motels, condo rentals,
restaurants, nght life, attractions, Spring Break , golf, local artists, and beach news.">
<style type="text/css">
<!--
a:link { font-color: #000000; text-decoration: none}
a:visited { font-color: #9900FF; text-decoration: none}
a:hover { font-weight: normal; color: #FF0000; text-decoration: none}
a:active { font-color: #FF9900; text-decoration: none}
-->
</style>

</head>

<body bgcolor="#FFFFFF">
<table width="750" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="451" bordercolor="#CC9900">
<table width="750" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFeebb">
<!--DWLayoutTable-->
<tr valign="top">
<td width="1" height="90"></td>
<td colspan="2"> <p align="center"><img src="../images/pcbanner12f.psd.gif" alt="Panama City Beach Now" width="750" height="90"></p></td>
</tr>
<tr>
<td height="119"></td>
<td width="750" colspan="2" rowspan="2" valign="top" bgcolor="#FFEEBB"><h2 align="center"><font face="Arial, Helvetica, sans-serif">
<br>
<font color="#003366"> eNews Signup Confirmation</font></font></h2>
<p align="left"> Thank you for signing up for the Beach eNews,
<%= Request("Name" %> </p>
<p align="left">You used the e-mail address: <%= Request("Email" %></p>
<p align="left"> <img src="../images/arrow.gif" width="22" height="19" align="top"><font face="Arial, Helvetica, sans-serif"><span class="para"><a href="javascript:history.go(-1);">Previous
Page</a></span></font> <a href="../index.html"></a></p>
<p align="left"> </p>
<p> </p>
<p> </p>
<p> </p>
<p align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">©
Copyright Panama City Beach Now 2004</font></p></td>
</tr>
<tr>
<td height="221"></td>
</tr>
<tr>
<td height="19"></td>
<td width="127"> </td>
<td width="623" valign="top"></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
Replied 08 Dec 2004 22:46:24
08 Dec 2004 22:46:24 Jim Moore replied:
Lee'
I fForgot to mention in my last post that I didn't change my insert statement to use a request.query string variable. I did create a Request. Form variable using my bindings panel for "name" and "email." I inserted these variables in the text on my confirm page,
Jim
Replied 10 Dec 2004 14:18:07
10 Dec 2004 14:18:07 Lee Diggins replied:
Hi Jim

Sorry for the delay getting back to you, been manic here running up to the Christmas break as today is my last day in work until the New Year <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Anyway, back to your problem.

Quick fix, change your form to GET!

Longer winded fix to use FORM below:

First, fix your insert record behaviour so it does what it's meant to do, leaving your form set to the METHOD of your choice, either POST or GET. At the moment it's set to POST so leave it as that. To make sure your insert behaviour functions as expected, remove the insert behaviour, then re-apply it, setting the appropriate values, redirect etc..

Second the confirmation page. The reason that request.form doesn't work on this page, is that any submitted form data is only available from the ASP querystring collection or form collection for the life of the processing page recieving the form data, except if you use the Server.Tranfer and Server.Execute methods, don't worry about these now. The form you have created posts back to itself and is pocessed by the same page, once the insert command is complete, the page uses Response.Redirect to the confirmation page and the transactions on the server - your submitted data is destroyed, so when you try to get something from the Form collection in ASP, the collection is empty, that's why you cannot show the users name.

So why does your pages partly work one way and not the other? The reason the request.querystring form submission version works is to do with the functionality of the insert behaviour. The insert record behaviour includes these bits of code:

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString &lt;&gt; "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

And....

' append the query string to the redirect URL
If (MM_editRedirectUrl &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

What this is doing is taking any values passed using the querystring into the insert record behaviour, capturing them and then attaching them to the redirect URL so the form data you submit using the GET method is then appended to the redirect URL therefore passing the form data to the next page - your confirmation page - which then in turn pulls the data from the resubmitted data (in the eyes of ASP), from the querystring collection, meaning your form data has been submitted twice to the ASP engine, once by your form, then again by the insert record behaviour.

When you use the POST method, the querystring will not contain your form data and so, regarding the insert behaviour script above, it cannot append the form data to the URL as it didn't exist in the querystring in the first place as you are using POST. The way around this is to add the form data to the quesrystring yourself by changing the redirect line, from this:

MM_editRedirectUrl = "confirm-signup.asp"

to this:

MM_editRedirectUrl = "confirm-signup.asp?name=" & Request.Form("Name"

(By the way your Name input field on your form has different ID and Name attributes, change it buddy)

You can then see the name being passed to the confirmation page in the querystring and retrieve the value on the confirmation page using Request.QueryString("Name", this will apply regardless of which form submission method you use POST or GET.

So in summary....

.... if you use GET (not good for sensitive data) the form data will be passed to your confirmation page by the insert record server behaviour. If you use POST, you need to edit the redirect line in the insert record server behaviour and add the form data (Request.Form("Name) to the querystring, adding the ?Name= as well.

Hope this makes sense Jim, a bit long winded I know, but I'm sure you would rather understand what's happening rather than just being told how to fix it!

Post back if unsure or if you have further questions.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 10 Dec 2004 16:05:36
10 Dec 2004 16:05:36 Jim Moore replied:

Lee,

Thanks for the great explanation and help.
Jim
Replied 10 Dec 2004 16:13:46
10 Dec 2004 16:13:46 Lee Diggins replied:
Got it working?

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 10 Dec 2004 22:14:32
10 Dec 2004 22:14:32 Jim Moore replied:
Lee,
Thanks to you I got it working. I also discovered that all of my request form variables created in my bindings panel are displayed on my confirm-signup.asp page when I change
the redirect code in my subscriber-signup.asp page from
MM_editRedirectURL = "confirmPage.asp" to
MM_editRedirectURL = "confirmPage.asp?" & Request.Form
It does this without my adding the variables "Name" and "Email" to the redirect code. I hope that others using Matt's email newsletter using Smart Mailer will benefit from your solution and explanation,
Cheers,
Jim

Reply to this topic