Jump to content

Function is not working..


bugzy

Recommended Posts

I have this code on my user registration form

 

<?php

$flg = "";
$error = "";
if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"];

switch ($flg) {
	case "yellow":
		$error = "<br><font class=\"txt12_red\">That Email Address already exists in our Database.<br>Please Select Another.<BR></font>";
		break;
	case "red":
		$error = "<br><font class=\"txt12_red\">Please fill out all the required fields.<br>Please Try Again.<BR></font>";
		break;
	case "blue":
		$error = "<br><font class=\"txt12_red\">Your Session has Expired.<br>Please Login Again.</font><BR>";
		break;
	case "pink":
		$error = "<br><font class=\"txt12_red\"><BR>The Special Code you entered is not valid.<br>Please Try Again or Leave that field blank.	                      </font><BR>";
		break;
	case "white":
		$error = "<br><font class=\"txt12_red\"><BR>The fields are too long for our Database.<br>Please correct your data via this form.</font>                      <BR>";
		break;
	default:
		$error = "";
} ?>

 

 

and the registered form / page I have this validation and function

 

<?php

// check to see if these variables have been set...

	if ((!isset($_SESSION["fname"])) || (!isset($_SESSION["lname"])) || (!isset($_SESSION["email"])) ||  (!isset($_SESSION["phone"]))
	 || (!isset($_SESSION["city"])) || (!isset($_SESSION["status"])) || (!isset($_SESSION["province"]))) 

		{
			 resendToForm("?flg=red");
		}

// form variables must have something in them...

	if ($_SESSION['fname'] == "" || $_SESSION['lname'] == "" || $_SESSION['email'] == "" || $_SESSION['phone'] == "" || $_SESSION['city'] == "" 		  || $_SESSION['status'] == "" || $_SESSION['province'] == "") 
		{
			resendToForm("?flg=red");
		}

// make sure fields are within the proper range...

	if (strlen($_SESSION['fname']) > 35 || strlen($_SESSION['lname']) > 35 || strlen($_SESSION['email']) > 35
    || strlen($_SESSION['phone']) > 35 || strlen($_SESSION['city']) > 35 || strlen($_SESSION['status']) > 35 
	|| strlen($_SESSION['province']) > 35 || strlen($_SESSION['password']) > 30) 
		{
			resendToForm("?flg=white");
		}




function resendToForm($flags) {
		reset ($_POST);
		// store variables in session...
		while (list ($key, $val) = each ($_POST)) {
			$_SESSION[$key] = $val;
		}	
		// go back to the form...
		//echo $flags;
		header("Location: ./registration_form.php".$flags);
		exit;
} ?>

 

 

 

The validation is working as it goes back to user registration form, the problem is it's not displaying the error on

<?php echo $error; ?>

 

 

What seems to be the problem? anyone?

 

Link to comment
Share on other sites

A redirect makes a completely new request to the server. What exactly are you expecting to be within the $error variable?

 

Hey thorpe. Thanks or the response again..

 

I'm expecting that $error will show this error message.

 

<?php

$flg = "";
$error = "";
if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"];

switch ($flg) {
	case "yellow":
		$error = "<br><font class=\"txt12_red\">That Email Address already exists in our Database.<br>Please Select Another.<BR></font>";
		break;
	case "red":
		$error = "<br><font class=\"txt12_red\">Please fill out all the required fields.<br>Please Try Again.<BR></font>";
		break;
	case "blue":
		$error = "<br><font class=\"txt12_red\">Your Session has Expired.<br>Please Login Again.</font><BR>";
		break;
	case "pink":
		$error = "<br><font class=\"txt12_red\"><BR>The Special Code you entered is not valid.<br>Please Try Again or Leave that field blank.	                      </font><BR>";
		break;
	case "white":
		$error = "<br><font class=\"txt12_red\"><BR>The fields are too long for our Database.<br>Please correct your data via this form.</font>                      <BR>";
		break;
	default:
		$error = "";
} ?>

 

 

So if a user didn't fill up a certain field.. The code below will validate it and resend him/her to the registration form and the error message from above will show up using "echo $error;" which is the "Please fill out all the required fields"

 

<?php

// check to see if these variables have been set...

	if ((!isset($_SESSION["fname"])) || (!isset($_SESSION["lname"])) || (!isset($_SESSION["email"])) ||  (!isset($_SESSION["phone"]))
	 || (!isset($_SESSION["city"])) || (!isset($_SESSION["status"])) || (!isset($_SESSION["province"]))) 

		{
			 resendToForm("?flg=red");
		}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.