I have a form that has the action pointing to a PHP script that I have written and that validates the form and emails the results (it works fine except for the session handling part).
It's a fairly long form and I'm trying to make my form save state for the user, so if they do not fill out the form completely they will be redirected to another page (identical to the original form) but with the form values still entered for them. -- My problem is that the variables are not able to be accessed for some reason.
I have tried alot of different things and I can't get my redirect page to have access to the variables, I even have the PHPSESSID variable hard coded into the query string of the redirect. I think my problem might have something to do with the script using functions?? I don't know at this point ...I'm just now getting used to PHP's session handling functions.
ANY HELP WOULD BE APPRECIATED!
#1 MY BASIC FORM'S ACTION:
(there is more to my script but I chopped it up for simplicity, I believe these functions are the ones I am having problems with)
<?php
function decode_vars(){
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
if (getenv("REQUEST_METHOD" == "GET"{
$a = $HTTP_GET_VARS;
} else {
$a = $HTTP_POST_VARS;
}
return $a;
}
function strip_bad_stuff($data){ //SSI security fix part 2
while(list($key,$val) = each ($data)){
if ($val){
$temp = $val;
$data[$key] = eregi_replace("<!--(.|\n)*-->","[SSI REMOVED]",$val);
if ($temp != $data[$key]){
error_log("[HMM] SSI Found and Removed. (".getenv("REMOTE_ADDR"."", 0);
}
}
}
return $data;
}
function error($errors){
global $form;
if ($errors){
if ($form["missing_fields_redirect"]){
Header("Location: ".$form[missing_fields_redirect]."?PHPSESSID=".session_id());
exit;
} else {
print "<HTML>\n<HEAD>\n";
print "<TITLE>Error</TITLE>\n";
if($form["css"]){
print "<link rel=\"stylesheet\" href=\"".$form["css"]."\">\n";
}
print "</HEAD>\n\n";
print "<BODY".$form["bgcolor"].$form["text_color"].$form["link_color"].$form["alink_color"].$form["vlink_color"].$form["background"]."\">\n";
print "<H2>The following errors were found:</H2><BR>\n";
while (list($key,$val) = each ($errors)) {
print $val . "<BR>\n";
}
print "<BR>Please use the <a href=\"javascript: history.back();\">back</a> button to correct these errors.<BR>\n";
print "</BODY>\n</HTML>";
}
}
}
function check_required($form){
global $errors;
$problem = true;
if (!$form["recipient"]) {
$problem = false;
$errors[] = "There is no recipient to send this mail to.";
}
if ($form["required"]){
$splitstring = split(",",$form["required"]);
for($x=0; $x < count($splitstring); $x++){
if (!$form[$splitstring[$x]]) {
$problem = false;
$errors[] = "Required value (<b>" . $splitstring[$x] . "</b>) is missing.";
}
}
}
return $problem;
}
$form = strip_bad_stuff(decode_vars());
if(!isset($sessed))
{session_start();
session_register("form"
$sessed = 1;
session_register("sessed"
}
else
{session_destroy();
session_unregister("form"
session_unregister("sessed"
session_start();
session_register("form"
$sessed = 1;
session_register("sessed"
}
if(check_required($form))
# it never get's to the mailing part
mail();
#2 BASIC MISSING FIELDS PAGE CODE:
<?php session_start(); ?>
<html>
<head>
</head>
<body>
<form name="whatever" action="myscript.php">
<input type="hidden" name="required" value="firstname"><input type="hidden" name="missing_fields_redirect" value="mssing_fields.php">
<input type="text" name="firstname" value="<?php print "$form[firstname]"; ?>">
</form>
</body>
</html> - PAINKILLER
It's a fairly long form and I'm trying to make my form save state for the user, so if they do not fill out the form completely they will be redirected to another page (identical to the original form) but with the form values still entered for them. -- My problem is that the variables are not able to be accessed for some reason.
I have tried alot of different things and I can't get my redirect page to have access to the variables, I even have the PHPSESSID variable hard coded into the query string of the redirect. I think my problem might have something to do with the script using functions?? I don't know at this point ...I'm just now getting used to PHP's session handling functions.
ANY HELP WOULD BE APPRECIATED!
#1 MY BASIC FORM'S ACTION:
(there is more to my script but I chopped it up for simplicity, I believe these functions are the ones I am having problems with)
<?php
function decode_vars(){
global $HTTP_POST_VARS;
global $HTTP_GET_VARS;
if (getenv("REQUEST_METHOD" == "GET"{
$a = $HTTP_GET_VARS;
} else {
$a = $HTTP_POST_VARS;
}
return $a;
}
function strip_bad_stuff($data){ //SSI security fix part 2
while(list($key,$val) = each ($data)){
if ($val){
$temp = $val;
$data[$key] = eregi_replace("<!--(.|\n)*-->","[SSI REMOVED]",$val);
if ($temp != $data[$key]){
error_log("[HMM] SSI Found and Removed. (".getenv("REMOTE_ADDR"."", 0);
}
}
}
return $data;
}
function error($errors){
global $form;
if ($errors){
if ($form["missing_fields_redirect"]){
Header("Location: ".$form[missing_fields_redirect]."?PHPSESSID=".session_id());
exit;
} else {
print "<HTML>\n<HEAD>\n";
print "<TITLE>Error</TITLE>\n";
if($form["css"]){
print "<link rel=\"stylesheet\" href=\"".$form["css"]."\">\n";
}
print "</HEAD>\n\n";
print "<BODY".$form["bgcolor"].$form["text_color"].$form["link_color"].$form["alink_color"].$form["vlink_color"].$form["background"]."\">\n";
print "<H2>The following errors were found:</H2><BR>\n";
while (list($key,$val) = each ($errors)) {
print $val . "<BR>\n";
}
print "<BR>Please use the <a href=\"javascript: history.back();\">back</a> button to correct these errors.<BR>\n";
print "</BODY>\n</HTML>";
}
}
}
function check_required($form){
global $errors;
$problem = true;
if (!$form["recipient"]) {
$problem = false;
$errors[] = "There is no recipient to send this mail to.";
}
if ($form["required"]){
$splitstring = split(",",$form["required"]);
for($x=0; $x < count($splitstring); $x++){
if (!$form[$splitstring[$x]]) {
$problem = false;
$errors[] = "Required value (<b>" . $splitstring[$x] . "</b>) is missing.";
}
}
}
return $problem;
}
$form = strip_bad_stuff(decode_vars());
if(!isset($sessed))
{session_start();
session_register("form"
$sessed = 1;
session_register("sessed"
}
else
{session_destroy();
session_unregister("form"
session_unregister("sessed"
session_start();
session_register("form"
$sessed = 1;
session_register("sessed"
}
if(check_required($form))
# it never get's to the mailing part
mail();
#2 BASIC MISSING FIELDS PAGE CODE:
<?php session_start(); ?>
<html>
<head>
</head>
<body>
<form name="whatever" action="myscript.php">
<input type="hidden" name="required" value="firstname"><input type="hidden" name="missing_fields_redirect" value="mssing_fields.php">
<input type="text" name="firstname" value="<?php print "$form[firstname]"; ?>">
</form>
</body>
</html> - PAINKILLER