Jump to content

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();

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.