Jump to content

Sending error message back to user who omitted fields in login form


mrherman

Recommended Posts

I need to learn some basics about sending a message back to the user concerning the form fields that the user omitted in a login form.  So far, I've tried placing the error message in a $_POST array variable, but when I redirect the user back to the login form, the $_POST message is not available.

 

My structure is: index.php --> login_form.php --> process_form.php --> (fields omitted) --> login_form.php

 

Is there a tutorial that addresses this common procedure?

 

I used phpFreaks search, but couldn't come up with a solution from existing posts.  Probably my search was not well-formed.

 

Thanks!

$_POST is only available when you submit a form.

you need to put the variables in $_SESSION, that will make them available on every page, as long as you add session_start(); to the beginning of every page, before any output.

 

Hope this helps,

As WebStyles said, you have to use $_SESSION.

 

Here's a simplified class that can handle flash messages for you:

class FlashMessage {

public static function wirte($message) {
	self::_startSession();
	$_SESSION['flash.message'] = $message;
}

public static function check() {
	self::_startSession();
	if (isset($_SESSION['flash.message'])) {
		$m = $_SESSION['flash.message'];
		unset($_SESSION['flash.message']);
		return $m;
	} else {
		return null;
	}
}

protected static function _startSession() {
	if (session_id() === '') {
		session_start();
	}
}

}

 

To use it you just do this in process_form.php

FlashMessage::write('You missed some fields!');

 

and then do this on login_form.php:

echo FlashMessage::check();

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.