after submit page....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

after submit page....

Post 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 .
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post 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.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
Last edited by protokol on Wed Jul 10, 2002 4:29 pm, edited 1 time in total.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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?
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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!
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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) )
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

sorry, that was a typo ... change it to $message

i edited the previous post to show this change as well
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

k, no prob.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post 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 :) )
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

wait definetly not session_register that didn't work

do i have to have some predefined variable called _SESSION or something?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try changing $_SESSION to $HTTP_SESSION_VARS
Post Reply