Forum Moderators: coopster

Message Too Old, No Replies

Help please with redirect

         

fvdvhome

3:28 am on Apr 22, 2010 (gmt 0)

10+ Year Member



Hello, I just created a basic contact-us html page.

I would like the user to see a thank you page right after the submit form is clicked. When I tested it, I did receive an email with all the form entered information. However, after clicking the Submit button, it defaults to my home page. I can't figure out how to change it to a simple thank you page. I'm using the free php option available from my hosting site. It automatically uploaded the following files: webformmailer.php, gdform.php, dbboon(directory) with a file named proxy.php inside.

Is there an easy way to have it go to a thank you page (that I can format) instead of my home page?

Thank you in advance.

Regards,

Frank

[edited by: eelixduppy at 4:08 am (utc) on Apr 22, 2010]
[edit reason] no personal URLs, please [/edit]

Matthew1980

6:58 am on Apr 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there fvdvhome,

Welcome to the forum,

The easiest thing to to do would be to post the code that has the redirect instruction in it, from there we can help you figure out what is wrong :)

As you said you have it at present defaulting to the homepage, post the form portion of the contact page too, this will give us an idea of how things are setup - on the same note try not to post HUGE pieces of code, try to keep it to the specifics.

Cheers,
MRb

fvdvhome

1:38 pm on Apr 22, 2010 (gmt 0)

10+ Year Member



Hi Matthew, thank you very much for getting back to me. I'm not sure which file (html-contact us page or script) has the redirect code. I hope you don't mind, I will list all the codes below:

webformmailer.php:
<?php

if ( !isset($_SERVER['SPI'])) {
die();
}

if (!isset($_SERVER['DOCUMENT_ROOT'])) {
echo("CRITICAL: we seem to be running outside of the norm.\n");
header("Location: [".$_SERVER["HTTP_HOST"]."...]
die("CRITICAL: Document root unavailable.\n");
}

$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET") {
$query_vars = $_GET;
}
elseif ($request_method == "POST") {
$query_vars = $_POST;
}

reset($query_vars);
function customsort($a,$b) {
// $a is array for form vars, $b is comma seperated case sensitive field order
// this is case sensitive -- good idea to hrc that.
$data = array();
if ( strstr($b,',') == FALSE ) {
$b = $b.",";
}
$ordering = split(',',$b);
foreach ($ordering as $orderitem) {
if ( ($orderitem != null) && ($orderitem != "") ) {
if (isset($a[$orderitem])) {
$data[$orderitem] = $a[$orderitem];
}
}
}
foreach ($a as $key=>$val) {
$data[$key] = $a[$key];
}
return $data;
}

function xmlentities($string) {
return str_replace ( array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $string);
}

$t = date("U");

$formhomedir = preg_replace('/.*\/home\/content/','',$_SERVER['DOCUMENT_ROOT']);
$formhomedir = explode('/',$formhomedir);
if (count($formhomedir) <= 4) {
$formhome="/home/content/".$formhomedir[1]."/".$formhomedir[2]."/data/";
}
else {
$formhome="/home/content/".$formhomedir[1]."/".$formhomedir[2]."/".$formhomedir[3]."/".$formhomedir[4]."/data/";
}

$file_order = ".default";
$file_format = ".text";
$file_interval = ".15m";
$field_order = "";

if (isset($query_vars['form_order'])) {
if ($query_vars['form_order'] != "alpha") {
$field_order=$query_vars['form_order'];
$file_order=".custom";
$query_vars = customsort($query_vars,$field_order);
}
else {
switch ($query_vars['form_order']) {
case "alpha":
uksort($query_vars,'strnatcasecmp');
$file_order=".alpha";
break;
default:
$file_order=".default";
break;
}
}
}

if (isset($query_vars['form_format'])) {
switch ($query_vars['form_format']) {
case "csv":
$file_format = ".csv";
break;
case "html":
$file_format = ".html";
break;
case "xml":
$file_format = ".xml";
break;
case "text":
case "default":
default:
$file_format = ".text";
break;
}
}

if (isset($query_vars['form_delivery'])) {
switch ($query_vars['form_delivery']) {
case "hourly":
$file_interval = ".60m";
break;
case "hourly_digest":
$file_interval = ".60mc";
break;
case "daily":
$file_interval = ".24h";
break;
case "daily_digest":
$file_interval = ".24hc";
break;
case "digest":
$file_interval = ".15mc";
break;
case "default":
default:
$file_interval = ".15m";
break;
}
}

$file = $formhome."form_".$t.$file_order.$file_format.$file_interval;
$fp = fopen($file,"w");

reset($query_vars);
switch ($file_format) {
case ".csv":
$csvkeys = "";
$csvvals= "";
$firsttime = "";
while (list ($key, $val) = each ($query_vars)) {
if ( ($key == "form_order") ||
($key == "form_format") ||
($key == "form_delivery") ||
($key == "redirect") ) {
}
else {
if ($csvkeys != "") {
$firsttime=",";
}
$tmpkey=escapeshellcmd($key);
$csvkeys = $csvkeys.$firsttime."'".$tmpkey."'";
$tmpval=escapeshellcmd($val);
$csvvals = $csvvals.$firsttime."'".$tmpval."'";
}
}
fputs($fp,"$csvkeys\n");
fputs($fp,"$csvvals\n");
break;
case ".html":
fputs($fp,"<table border=\"1\" cellspacing=\"1\" cellpadding=\"2\">\n");
break;
case ".xml":
fputs($fp,"<form>\n");
break;
}

reset($query_vars);
while (list ($key, $val) = each ($query_vars)) {
if ($key == "redirect") {
$landing_page = $val;
}
if ( ($key == "form_order") ||
($key == "form_format") ||
($key == "form_delivery") ||
($key == "redirect") ) {

}
else {
switch ($file_format) {
case ".html":
fputs($fp,"\t<tr>\n");
fputs($fp,"\t\t<td><b>$key</b></td>\n");
fputs($fp,"\t\t<td>$val</td>\n");
fputs($fp,"\t</tr>\n");

break;
case ".csv":
// content is already output
break;
case ".xml":
fputs($fp,"\t<field>\n");
fputs($fp,"\t\t<fieldname>".xmlentities($key)."</fieldname>\n");
fputs($fp,"\t\t<fieldvalue>".xmlentities($val)."</fieldvalue>\n");
fputs($fp,"\t</field>\n");
break;
case ".text":
default:
fputs($fp,$key.": ".$val."\n");
break;
}
}
}

switch ($file_format) {
case ".html":
fputs($fp,"</table>\n");
break;
case ".xml":
fputs($fp,"</form>\n");
break;
}


fclose($fp);

if ($landing_page != "") {
header("Location: [".$_SERVER["HTTP_HOST"]."...]
}
else {
header("Location: [".$_SERVER["HTTP_HOST"]."...]
}


?>

gdform.php:
<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET"){
$query_vars = $_GET;
} elseif ($request_method == "POST"){
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");

$file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars)) {
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
fputs($fp,"$val\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
if ($key == "redirect") { $landing_page = $val;}
}
fclose($fp);
if ($landing_page != ""){
header("Location: [".$_SERVER["HTTP_HOST"]."...]
} else {
header("Location: [".$_SERVER["HTTP_HOST"]."...]
}


?>

dbboon(folder), proxy.php:
<?php

$version = '1.2';

if(isset($_GET['dbboon_version'])) {
echo '{"version":"' . $version . '"}';
exit;
}

function dbboon_parseHeaders($subject) {

global $version;

$subject = trim($subject);
$parsed = Array();
$len = strlen($subject);
$position = $field = 0;
$position = strpos($subject, "\r\n") + 2;

while(isset($subject[$position])) {

$nextC = strpos($subject, ':', $position);
$fieldName = substr($subject, $position, ($nextC-$position));
$position += strlen($fieldName) + 1;
$fieldValue = NULL;

while(1) {
$nextCrlf = strpos($subject, "\r\n", $position - 1);
if(FALSE === $nextCrlf) {
$t = substr($subject, $position);
$position = $len;
} else {
$t = substr($subject, $position, $nextCrlf-$position);
$position += strlen($t) + 2;
}

$fieldValue .= $t;
if(!isset($subject[$position]) || (' ' != $subject[$position] && "\t" != $subject[$position])) {
break;
}
}

$parsed[strtolower($fieldName)] = trim($fieldValue);
if($position > $len) {
echo '{"result":false,"error":{"code":4,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
exit;
}
}
return $parsed;
}

if(!function_exists('http_build_query')) {
function http_build_query($data, $prefix = '', $sep = '', $key = '') {
$ret = Array();
foreach((array) $data as $k => $v) {
if(is_int($k) && NULL != $prefix) {
$k = urlencode($prefix . $k);
}
if(!empty($key) || $key === 0) {
$k = $key . '[' . urlencode($k) . ']';
}
if(is_array($v) || is_object($v)) {
array_push($ret, http_build_query($v, '', $sep, $k));
} else {
array_push($ret, $k . '=' . urlencode($v));
}
}
if(empty($sep)) {
$sep = '&';
}
return implode($sep, $ret);
}
}

$host = 'dbexternalsubscriber.secureserver.net';
$get = http_build_query($_GET);
$post = http_build_query($_POST);
$url = $get ? "?$get" : '';
$fp = fsockopen($host, 80, $errno, $errstr);

if($fp) {

$payload = "POST /embed/$url HTTP/1.1\r\n";
$payload .= "Host: $host\r\n";
$payload .= "Content-Length: " . strlen($post) . "\r\n";
$payload .= "Content-Type: application/x-www-form-urlencoded\r\n";
$payload .= "Connection: Close\r\n\r\n";
$payload .= $post;

fwrite($fp, $payload);

$httpCode = NULL;
$response = NULL;
$timeout = time() + 15;

do {
while($line = fgets($fp)) {
$response .= $line;
if(!trim($line)) {
break;
}
}
} while($timeout > time() && NULL === $response);

$headers = dbboon_parseHeaders($response);
if(isset($headers['transfer-encoding']) && 'chunked' === $headers['transfer-encoding']) {
do {
$cSize = $read = hexdec(trim(fgets($fp)));
while($read > 0) {
$buff = fread($fp, $read);
$read -= strlen($buff);
$response .= $buff;
}
$response .= fgets($fp);
} while($cSize > 0);
} else {
preg_match('/Content-Length:\s([0-9]+)\r\n/msi', $response, $match);
if(!isset($match[1])) {
echo '{"result":false,"error":{"code":3,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
exit;
} else {
while($match[1] > 0) {
$buff = fread($fp, $match[1]);
$match[1] -= strlen($buff);
$response .= $buff;
}
}
}

fclose($fp);

if(!$pos = strpos($response, "\r\n\r\n")) {
echo '{"result":false,"error":{"code":2,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
exit;
}

echo substr($response, $pos + 4);

} else {
echo '{"result":false,"error":{"code":1,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
exit;
}

Code from my html-contact us page (form area):
<div id=form>
<form id="form1" name="form1" method="post" action="/webformmailer.php">
<table width="100%" border="0" cellpadding="6">
<tr>
<td width="341"><div align="right" class="style1">
<label for="email"></label>
Your email:</div></td>
<td width="429"><div align="left"><span class="style1">
<input name="email" type="text" id="email" size="35" maxlength="90" />
</span></div></td>
</tr>
<tr>
<td><div align="right" class="style1">
<label for="name">Name:</label>
</div></td>
<td><div align="left"><span class="style1">
<input name="name" type="text" id="name" size="35" maxlength="80" />
</span></div></td>
</tr>
<tr>
<td><div align="right" class="style1">
<label for="phone">Phone:</label>
</div></td>
<td><div align="left"><span class="style1">
<input name="phone" type="text" id="phone" size="35" maxlength="12" />
</span></div></td>
</tr>
<tr>
<td><div align="right" class="style1">Photography Services:</div></td>
<td><div align="left" class="style1">
<input name="real estate" type="checkbox" id="real estate" value="realestate" />
<label for="real estate">Real Estate</label>
<p>
<input name="portraits" type="checkbox" id="portraits" value="portraits" />
<label for="portraits">Portraits and Corporate Head Shots</label>
</p>
<p>
<input name="products" type="checkbox" id="products" value="products" />
<label for="products">Products</label>
</p>
<p>
<input name="webdesign" type="checkbox" id="webdesign" value="webdesign" />
<label for="webdesign">Web Design</label>
</p>
</div></td>
</tr>
<tr>
<td><div align="right" class="style1">
<label for="comments">Comments:</label>
</div></td>
<td><div align="left"><span class="style1">
<textarea name="comments" id="comments" cols="33" rows="5"></textarea>
</span></div></td>
</tr>
<tr>
<td><div align="right">
<label for="clear"></label>
<input type="reset" name="clear" id="clear" value="Reset Form" />
</div></td>
<td><div align="left">
<label for="submit"></label>
<input type="submit" name="submit" id="submit" value="Submit Form" />
</div></td>
</tr>
</table>
</form>

Thanks again.

Frank

rocknbil

5:23 pm on Apr 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look at this:

while (list ($key, $val) = each ($query_vars)) {
if ($key == "redirect") {
$landing_page = $val;
}

Which is what I suspected, as is the case with most prepackaged mailers: you just need to add this to your initial form:

<input type="hidden" name="redirect" value="https://example.com/thank-you.html">

Used https so we don't get the silly link thingy after the URL, you would likely want to just use http:

fvdvhome

9:58 pm on Apr 23, 2010 (gmt 0)

10+ Year Member



Thank you, Thank you! It worked perfect! :)

Regards,

Frank