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
https://forums.phpfreaks.com/topic/260065-function-is-not-working/
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");
		}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.