Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Session Handling Problem

Status
Not open for further replies.

pain4u

Technical User
Jun 26, 2001
64
US
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(&quot;REQUEST_METHOD&quot;) == &quot;GET&quot;){
$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(&quot;<!--(.|\n)*-->&quot;,&quot;[SSI REMOVED]&quot;,$val);
if ($temp != $data[$key]){
error_log(&quot;[HMM] SSI Found and Removed. (&quot;.getenv(&quot;REMOTE_ADDR&quot;).&quot;)&quot;, 0);
}
}
}
return $data;
}

function error($errors){
global $form;
if ($errors){
if ($form[&quot;missing_fields_redirect&quot;]){
Header(&quot;Location: &quot;.$form[missing_fields_redirect].&quot;?PHPSESSID=&quot;.session_id());
exit;
} else {
print &quot;<HTML>\n<HEAD>\n&quot;;
print &quot;<TITLE>Error</TITLE>\n&quot;;
if($form[&quot;css&quot;]){
print &quot;<link rel=\&quot;stylesheet\&quot; href=\&quot;&quot;.$form[&quot;css&quot;].&quot;\&quot;>\n&quot;;
}
print &quot;</HEAD>\n\n&quot;;
print &quot;<BODY&quot;.$form[&quot;bgcolor&quot;].$form[&quot;text_color&quot;].$form[&quot;link_color&quot;].$form[&quot;alink_color&quot;].$form[&quot;vlink_color&quot;].$form[&quot;background&quot;].&quot;\&quot;>\n&quot;;
print &quot;<H2>The following errors were found:</H2><BR>\n&quot;;
while (list($key,$val) = each ($errors)) {
print $val . &quot;<BR>\n&quot;;
}
print &quot;<BR>Please use the <a href=\&quot;javascript: history.back();\&quot;>back</a> button to correct these errors.<BR>\n&quot;;
print &quot;</BODY>\n</HTML>&quot;;
}
}
}

function check_required($form){
global $errors;
$problem = true;
if (!$form[&quot;recipient&quot;]) {
$problem = false;
$errors[] = &quot;There is no recipient to send this mail to.&quot;;
}
if ($form[&quot;required&quot;]){
$splitstring = split(&quot;,&quot;,$form[&quot;required&quot;]);
for($x=0; $x < count($splitstring); $x++){
if (!$form[$splitstring[$x]]) {
$problem = false;
$errors[] = &quot;Required value (<b>&quot; . $splitstring[$x] . &quot;</b>) is missing.&quot;;
}
}
}
return $problem;
}

$form = strip_bad_stuff(decode_vars());

if(!isset($sessed))
{session_start();
session_register(&quot;form&quot;);
$sessed = 1;
session_register(&quot;sessed&quot;);
}
else
{session_destroy();
session_unregister(&quot;form&quot;);
session_unregister(&quot;sessed&quot;);
session_start();
session_register(&quot;form&quot;);
$sessed = 1;
session_register(&quot;sessed&quot;);
}

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=&quot;whatever&quot; action=&quot;myscript.php&quot;>
<input type=&quot;hidden&quot; name=&quot;required&quot; value=&quot;firstname&quot;><input type=&quot;hidden&quot; name=&quot;missing_fields_redirect&quot; value=&quot;mssing_fields.php&quot;>
<input type=&quot;text&quot; name=&quot;firstname&quot; value=&quot;<?php print &quot;$form[firstname]&quot;; ?>&quot;>
</form>
</body>
</html> - PAINKILLER
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top