...

View Full Version : Managing a Form POST response



murgeltd
07-09-2007, 10:58 PM
Hi All,

I have created a form with multiple hidden/text fields that gets POST(ed) to a third party e-marketing account.

The webpage that it is posted to then replys with a single line response with two bits of information

I.e. '0,invalid email' but more often that not hopefully it will return '1, success'

This is as far as I have got.

What I need is some code that takes this response, and if '1' redirects to another page, if it is a fail (i.e. 0) takes the user to the form page again with error message or if easier another page which explaining the error then redirecting the user back to the form page.

If you want to test how far I have got goto this test page and fill out the form - currently no form validation so enter a correctly formatted email for positive response - http://217.154.121.3/M-urge/downloads/ssTrial_test.asp

Any ideas?

Regards

Andy

miranda
07-10-2007, 12:23 AM
is the following address on your webserver? http://server1.streamsend.com/newstreamsend/mini-api.php


If not then I would use AJAX to send the information to that site and parse the reply to handle what you are asking. At that point it is just a matter of looking for the 1 or 0 and then taking the appropriate action.


If it is your webserver, then you can write some code to take the user back to the site dependant on the value returned.

murgeltd
07-10-2007, 11:04 AM
The resulting page is not on my webserver, it is a third party e-marketing mini-api for submitting new subscriber information to a registered list.

Having not even looked at AJAX is there a simple ASP code that can be used? I know the process just not the code (see pseudo code below). If it has to be AJAX what is the best resourse to use to learn it?

Pseudo Code:
POST Form
Capture response result, reason
If result = 1
page redirect = "http://xyz.asp"
If result = 0
page redirect = "http://error.asp?=reason"
End

That way I can then display the actual error to the user in another page.

It's just the capture of the two bits of information that is causing problems.

Regards

Andy

Daemonspyre
07-10-2007, 02:08 PM
How is the reply sent back? QueryString or Response?

i.e. How do you get the string?

Here's an idea (based on QueryStrings and using session variables) --

POST FORM

if Request.Querystring("Result") = "1,Success" then
response.redirect("success.asp")
elseif Request.Querystring("Result") = "0,invalid email" then
session("showError") = true
response.redirect("your_form.asp")
end if
'
'
ON THE FORM


<% if session("showError") = true then %>
<div> There was an error processing your request. Please check all fields and try again</div>
<% Session.Contents.Remove("showError")
end if %>

Session variables persist throughout pages, without having to show the "reason" in the address bar. Post the error back to your form (one less click = one more client). Once the variable is used, destroy it.

You can even customize this to check the form and tell the user exactly which error has occurred.

Let me know if you need more help.

murgeltd
07-10-2007, 11:44 PM
The result comes back in the form of one line, two variable response.
result,error message

result = 0 for fail and 1 for success
error message = reason for fail or it just displays 'success' if first variable is 1.

So I need to take this one line response, split it into two variable and perform a simple If, Else command on the first variable.

ASP code capturing and spliting this one line response would really really help.

Regards

Andy

Daemonspyre
07-11-2007, 01:57 PM
Andy --

Use the SPLIT command.



'strResult = result,errorMsg 'This line is just to store your results and is not needed. Your results should be in the form of a Querystring or a Response.

var1 = split(strResult,",")
'
if var1(0) = "1" then
response.redirect("success.asp")
else
response.redirect("error.asp")
end if
'

miranda
07-11-2007, 05:28 PM
Does the page the form is sent to redirect back to your site? Right now the page ends at the other server which is why I said to use AJAX as you can then get the response from that page, because if they do not direct the user back to a page on your site you have no way of handling the information.

If they redirect back to your site then you can easily do as Daemonspyre mentioned.

murgeltd
07-17-2007, 11:30 PM
You're right the other server does not redirect back to my site which is a real pain and why I am stuck at this point.

Do you have any specific coding pointers for using AJAX, and how can I spilt the two values into two variables? Having not used AJAX before is there any coding example or tutorials you can recommend.

Any help with AJAX code will be much appreciated?

Regards

Andy

Daemonspyre
07-18-2007, 12:06 AM
A quick and dirty tutorial on AJAX is here (http://www.w3schools.com/ajax).

As to splitting out the data into variables, it would also be a good time to learn JavaScript, if you don't already know it.

That way, variables are just as easy...


<script language="javascript">
var splitted = '<%= request.querystring("result") %>';
var splitted2 = splitted.split(',');

if(splitted2[0] == 1 ) { alert('Success!') }
if(splitted2[0] == 0 ) {
document.location.href = 'path_to_form.asp?error=' + splitted2[1];
}
</script>

miranda
07-20-2007, 07:01 PM
I thought about this and ASP and the XML object can do the same thing

So to handle this Just follow these steps.
1. change the action in your form tag to the following page which will reside on YOUR server -- xmlpage.asp

2. Create the xmlpage.asp using the code shown below

3. put some values in the response redirects or even handle the info on this page



xmlpage.asp


<%
Dim xml
Dim sResults
Dim sURL
Dim params

'fill in the values
params = "ss_username=" & Request.Form("ss_username") &_
"&ss_password=" & Request.Form("ss_password") &_
"&ss_listid=" & Request.Form("ss_listid") &_
"&ss_cmd=" & Request.Form("ss_cmd") &_
"&ss_else=" & Request.Form("ss_else") &_
"&mmtrial=" & Request.Form("mmtrial") &_
"&first_name=" & Request.Form("first_name") &_
"&lastname=" & Request.Form("lastname") &_
"&company=" & Request.Form("company") &_
"&phonenumber=" & Request.Form("phonenumber") &_
"&emailaddress=" & Request.Form("emailaddress")

'the url we are posting the data to
sURL = "http://server1.streamsend.com/newstreamsend/mini-api.php"

' Create an xmlhttp object:
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
' Opens the connection to the server.
xml.Open "POST", sURL, false
' add a header so that the page can handle the data
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

' Actually Sends the request and returns the data:
xml.Send(params)
'fills the variable
sResults = xml.responseText
Set xml = Nothing 'removes the object from server memory

'Response.Write sResults

'redirect the user depending on the response
If InStr(LCase(sResults),"success") Then
Response.Redirect ' send to success page
Else
Response.Redirect ' send to failure page
End If
%>

murgeltd
07-20-2007, 10:31 PM
Thank you so much for all your help. It works perfectly.

I have one question though...

on the bit of code that in xmlpage.asp than deals with the response, does the code split the result into two variables or is it just looking for the word success in the response.

If the later could I simply change the word "success" to "1" as this also tells me the insertion has been successful.

I guess the other part of that is if it is "0" could I just send the second part of the response through to the fail page using querystring. E.g. response.redirect "fail.asp?reason="[second part]"

I know what I'm trying to acheive but not explaining it very well. Basically the second part of the streamsend response is the reason for failure if the first part is a 0. I want to use that exact reason in the fail page.

Regards

Andy

miranda
07-21-2007, 06:24 AM
To answer the questions Yes, you can look for 1 instead of success. and Yes, you can pass the 0 or any other failure value passed. You do not need to split the string. The split function creates an array, and an array is not needed here.

Is failure always a 0 as in boolean false? or is there other failure codes? If there are other failure codes and they are always a single digit then it is really easy. if it is not a single digit it is still easy just a bit more complicated If you know the 1st character is the character to key off, just use the Left function.

so the if statement would become


If InStr(sResults,"1") Then
response.redirect "success.asp"
Else
response.redirect "fail.asp?reason=" & Left(sResults,1)
End If


however say they have a failure code of 25 or 237 or 4678 then you would need to also look at the comma and use that like so


If InStr(sResults,"1") Then
response.redirect "success.asp"
Else
'subtract 1 from the value returned from the InStr function because you do not want to include the comma.
'InStr starts counting at 1 for the 1st position NOT 0 if 0 is returned it means your string is not found
response.redirect "fail.asp?reason=" & Left(sResults,InStr(sResults,",")-1)
End If



of course if it is always a 0 then you can simply use

If InStr(sResults,"1") Then
response.redirect "success.asp"
Else
response.redirect "fail.asp?reason=0"
End If

btw if you are only going to pass 1 parameter in the querystring you can also use
response.redirect "fail.asp?" & Left(sResults,1)
or
response.redirect "fail.asp?" & Left(sResults,InStr(sResults,",")-1)
or
response.redirect "fail.asp?0"


to get that value just use
reason = Request.Querystring

murgeltd
07-22-2007, 10:32 PM
The numerical figure is a boolean value so I give your suggestion a go and see what happens.

The first part of the form is full of hidden values that get sent to the xml page, but I would rather I didn't put them in this page and just added them to the params = section.

At the moment I have:

params = "ss_username=" & Request.Form("ss_username") &_
"&ss_password=" & Request.Form("ss_password") &_
"&ss_listid=" & Request.Form("ss_listid") &_
"&ss_cmd=" & Request.Form("ss_cmd") &_
"&ss_else=" & Request.Form("ss_else") &_
"&trialpks=" & Request.Form("trialpks") &_
"&firstname=" & Request.Form("firstname") &_
"&lastname=" & Request.Form("lastname") &_
"&company=" & Request.Form("company") &_
"&phonenumber=" & Request.Form("phonenumber") &_
"&emailaddress=" & Request.Form("emailaddress")

If I just wanted to hard code the username and password into this part of code is it just:

"ss_username=xyz" &_
"&ss_password=abc" &_
"&ss_listid=" & Request.Form("ss_listid") &_
"&ss_cmd=" & Request.Form("ss_cmd") &_

It doesn't seems to be right.

Regards

Andy

miranda
07-23-2007, 12:47 AM
yes, if you don't want to include the hidden values you can just enter the value as you have shown.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum