Page 1 of 2

after submit page....

Posted: Wed Jul 10, 2002 12:51 pm
by fariquzeli
I have 2 pages where users submit info and it submits to a database and redirects them to a main page. The site uses session variabls. I was just wondering...

is there a way so i can make the main index.php page (the page that has the login info) detect whether or not a person has just submitted a form on a seperate page (one that is verified under the session variables) so that I can tell them in a little bold print message on the main page that their support request has been received and that it will be answered shortly?

Yet, when the user first logs in they goto the index.php page as well and I want to make sure they dont have messages saying your support request has been received if they haven't yet done anything.

if what i'm describing is too hard to understand i can try to explain more .

Posted: Wed Jul 10, 2002 12:59 pm
by fatalcure
well, not unless you pass a variable along w/ the URL you're redirecting to, I don't think so.

Why not display the message "your support request has been received" one the second page when you add the data to the database.

Then have a link back to the main index.php page or do a Meta redirect, where it automatically redirects the user after a specified amount of time, lets like after 10 secs, they'll be directed to the main page if they dont click on the link.

Posted: Wed Jul 10, 2002 1:56 pm
by protokol
This is how I do it:

I keep a $_SESSION['user_message'] variable which stores error messages, confirmations, etc. Then I use these two functions:

Code: Select all

function setUserMessage($message, $error=false) {
   session_start();
   if ($error)
      $_SESSION&#1111;'user_message'] = "<span style="color: red">$message</span>";
   else
      $_SESSION&#1111;'user_message'] = $message;
&#125;

function printUserMessage() &#123;
   session_start();
   if ($_SESSION&#1111;'user_message'] != "")
      echo $_SESSION&#1111;'user_message'];
   $_SESSION&#1111;'user_message'] = ""; // message has been displayed so reset it
&#125;
Now, whenever I want to tell the user something I do:

setUserMessage("Thanks for the information!");
setUserMessage("You must fill in required information!", true); // sets error message flag

In each script, I pick a spot that I want user messages to be displayed and I simply put:

<?php printUserMessage() ?>

Now, I have a nice user/error message system which I can put into any script.

Posted: Wed Jul 10, 2002 2:01 pm
by fariquzeli
So at the end of the submission form thing I would set a user message like you have

and then on the main page I would put the printuser message function call thingy and it would only print if a message was set on a seperate session page?

Posted: Wed Jul 10, 2002 2:03 pm
by fariquzeli
one more thing, would i have to type out those 2 functions on a seperate .php file and then have them included on all pages?

Posted: Wed Jul 10, 2002 2:04 pm
by protokol
Any time you use setUserMessage("some message"), the $_SESSION['user_message'] will remain active up until you call printUserMessage().

If you look in the printUserMessage() function, the last thing it does is:

$_SESSION['user_message'] = "";

So, now if you haven't called setUserMessage() again and the printUserMessage() function is called, nothing will be displayed.

Since it is a session variable, no matter what page you set it on, you can print it on any other page.

Posted: Wed Jul 10, 2002 2:04 pm
by protokol
fariquzeli wrote:one more thing, would i have to type out those 2 functions on a seperate .php file and then have them included on all pages?
Yes. Or put them into a script which is already included on all pages.

Posted: Wed Jul 10, 2002 2:38 pm
by fariquzeli
I see, thats pretty damn cool. I don't do much OOP

I'm working my way up to it and programming more of my own functions, thanks a bunch!

Posted: Wed Jul 10, 2002 3:01 pm
by protokol
Yes, the functions are very helpful when I have inherited classes .. put those bad boys in the parent class, and voila! Everyone gets user_messages! (with a few simple modifications to the code of course 8) )

Posted: Wed Jul 10, 2002 4:05 pm
by fariquzeli
I have one more question, one of the variables in the setUserMessage function is $msg.

Where is that variable defined in the function?

I dont see it defined when calling up the function either?

Posted: Wed Jul 10, 2002 4:28 pm
by protokol
sorry, that was a typo ... change it to $message

i edited the previous post to show this change as well

Posted: Wed Jul 10, 2002 4:30 pm
by fariquzeli
k, no prob.

Posted: Wed Jul 10, 2002 5:05 pm
by fariquzeli
one more question, I get an undefined variable _SESSION

what would I have to change in that part of the code to make it work for me?

make it say session_register instead?

(i'm a newbie :) )

Posted: Wed Jul 10, 2002 5:08 pm
by fariquzeli
wait definetly not session_register that didn't work

do i have to have some predefined variable called _SESSION or something?

Posted: Wed Jul 10, 2002 5:17 pm
by hob_goblin
try changing $_SESSION to $HTTP_SESSION_VARS