How To Control The Success and Fail Page Of a Host & Post Form?

Edwin

New member
Mar 17, 2007
329
3
0
I need to find a way to have a Host & Post form use my own success page and in case of a failure redirect the user back to the original form location.

Currently the form's success page is hosted on the domain that receives the form info and it's just a blank page with the word "success" being mentioned.

The fail page turns up a white screen with the word "fail" being mentioned.

If you've dealt with this sort of form posting stuff before I highly appreciate any advice you can give me.

Thanks!
 


you have to edit the file that <form action="" points to. That's probably where the form validation is happening.
 
Yeah, that's what I thought as well, I told my contact at the network if they could change the location of the Success and the Fail page and I'm being told I can use their response to direct the user to a specific location.


All I can find is what I initially thought and you just confirmed as well...I mean how the heck can I handle the response myself if the form validation is being done via a file that I can't access?
 
If you're using PHP then you'll want to take all of the data and use CURL to send it to their server. Then you get a success or fail response from their server and send the user to whatever page you want on your server.

If you're using .net you'd do this with httpwebresponse (I think - I haven't done .net in 4 years).
 
Hi Bradley,

It's an HTML form, with a similar line of code jryan posted:

Code:
<form action=""
So all information collected in the form will be posted to the file located where the form action points to.

So the main question would be:

Can a HTML form that makes use of the <form action="" function be edited as such so that it can direct the user to a specified location upon Success or Fail, without editing the file listed in the <form action="" ?

I'm not that knowledgeable about coding/programming to say for certain it can't be done, but from what I understand it can't.

Your thoughts and from everyone else on this is much appreciated!
 
He says that you collect your data using your form, then send to their server for validation, then you will get succes or fail reply - it will send fail or succes page right?-don't send your user there -just use this as "instruction" to send your user to your fail or succes page
 
He says that you collect your data using your form, then send to their server for validation, then you will get succes or fail reply - it will send fail or succes page right?
Correct, the file on the receiving server will apply the redirect to the Success or Fail page, which I don't have access to...yet the network tells me I can control the Success and Fail page locations? :confused:

This isn't possible to my understanding, if it is I would very much like to know how.
 
Ok , look you need to create or let someone to create script and point
<form action="yourscript"
Now this script should get your data and send it to "their validation' script,
that script will return success or fail page, but it will return it not to user browser , but to your script.
So based on what it returns redirect them where you want them to.
 
that script will return success or fail page, but it will return it not to user browser , but to your script
The form action posts to a file hosted on the network's server:

Code:
<form action='http://networks-post-domain.com/?filename' method='POST'>
I can't access that file.

Which makes it not possible to specify a Success or Fail page on my end.

Or am I wrong? :)
 
do you have access to change this?

<form action='http://networks-post-domain.com/?filename' method='POST'>

to

<form action='http://yourdomain.com/?filename' method='POST'>
 
Yes. :)

That's no problem.

Do you know of any example codes/scripts that could help me on my way?
Or keywords I can use to learn more about the subject?
 
LOL - that's exactly what I said to do up in my post.

You have the form post to your own PHP page. In that page you can do whatever you want.

For example on one of my sites I have to post to another site that collects leads. So I -
Send an e-mail of form values to our lead administrator.
Save the form values to our database.
Submit the form values via CURL to another companies API.
Get their response and redirect to a success page - in this case I do 100% validation behind the scenes so the only possible failure is if their API is down. And in that case the transfer is going to time out - but the user could care less about that so they get sent to a thank you page anyway.

Their API also immediately e-mails our lead administrator so that person gets 2 e-mails within a second of each other and the second e-mail says whether it was a success or failure. The reason I do it in the order above is because the API can be down (about 12 hours in 1.5 years so far) and in that case I still have my own copies of the data and can manually send it later for credit.

Hope that helps.
 
  • Like
Reactions: Edwin
LOL - that's exactly what I said to do up in my post.


Hahaha, you can't help it I'm as thick as a brick when it comes to programming.

Without the right documentation I have no idea where to begin putting that into code.

Your input is much appreciated Bradley. :)
 
So far no success guys,

The process should go like this right:

1: Form collects data
2: Form posts data via the form action to a script on my own domain
3: Script collects data and posts to external URL
4: Script redirects user to a specific location depending on Success or Fail message.

Reading through this tutorial it looks to me there is a step missing.
If I point the form action to process.php does process.php actually receive the submitted information like this?

Or would I first need to have an initial script that collects and pushes it to process.php?


* For reference purposes lets call this script below process.php *
Code:
<?php

//create array of data to be posted
[B]$post_data['firstName'] = 'Name';
$post_data['action'] = 'Register';[/B]
 //traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
 //create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
 //create cURL connection
$curl_connection = curl_init('http://hostyposty.com/?nb_offer=105&nb_site=51');
 //set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
 //set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
 //perform our request
$result = curl_exec($curl_connection);
 //show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);
 //close the connection
curl_close($curl_connection);
 ?>
(I know the script code above is incomplete as I would need to add the additional needed lines that correlate to the form field values.)

Here is a link to the lead form code.

#738736 - Pastie

How would I use the CURLOPT_FOLLOWLOCATION function to implement the redirect after a Success or Fail response?


Do I just point the form action URL in the form to process.php and then process.php collects the submitted info and posts it to the external URL I've listed in the process.php code?


Am I heading in the right direction with this? LOL
 
The CURLOPT_FOLLOWLOCATION part is not for redirecting the user. Your success or fail message is going to come from $result, so right below $result = curl_exec($curl_connection), where it says "show information regarding the request," you'll want to get rid of that stuff and put something like this instead:

if($result === 'success') {
header('Location: http://yoursuccesspage.com/');
}
elseif($result === 'failure') {
header('Location: http://backtotheform.com/');
}

No idea if that will work exactly as typed but that's the logic you need to apply.