eluzion Posted September 29, 2008 Share Posted September 29, 2008 I have one page setup that lists everything in the database and another page to add a new entry. As of now, when a new entry is added it simply redirects back to the main page that lists everything in the database. How would I go about adding a message at the top of that page (that lists everything in the database) to notify the user the data was successfully entered? Thanks! Link to comment https://forums.phpfreaks.com/topic/126361-notifying-user-on-successful-form-entry/ Share on other sites More sharing options...
trq Posted September 29, 2008 Share Posted September 29, 2008 A simple example. p1.php <?php session_start(); ?> <html> <head><title>form</title></head> <body> <?php echo if (isset($_SESSION['msg']) { echo "<p>" . $_SESSION['msg'] . "</p>"; unset($_SESSION['msg']); } ?> <form action="p2.php" method="post"> <input type="text" name="foo"> <input type="submit" name="submit"> </form> </body> </html> p2.php <?php session_start(); // process form and set $return to true / false respectively. if ($return) { $_SESSION['msg'] = "Form submitted successfully!"; header("Location: p1.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/126361-notifying-user-on-successful-form-entry/#findComment-653450 Share on other sites More sharing options...
eluzion Posted September 29, 2008 Author Share Posted September 29, 2008 Thanks for the reply. I'm guessing what this does is sends them to p2.php with the "Form submitted successfully" message and redirects them back to the original p1.php form? I'm hoping to be able to have the user be forwarded to the page with all the database entries and just place the "Form submitted successfully" message at the top of the page. I'm sure it's somewhere along the same lines of what you posted... just not too familiar with using sessions. Link to comment https://forums.phpfreaks.com/topic/126361-notifying-user-on-successful-form-entry/#findComment-653457 Share on other sites More sharing options...
eluzion Posted September 29, 2008 Author Share Posted September 29, 2008 Ah, figured it out. Placed this in the page with the form: $_SESSION['msg'] = "Form submitted successfully!"; Then added this to the page with all the database results: <?php session_start(); // process form and set $return to true / false respectively. if (isset($_SESSION['msg'])) { echo "<p>" . $_SESSION['msg'] . "</p>"; unset($_SESSION['msg']); } ?> I'm guessing the first piece of code defines what _SESSION['msg'] is and the second piece of code basically sees if it came from that page, then post that message... I think? Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/126361-notifying-user-on-successful-form-entry/#findComment-653462 Share on other sites More sharing options...
eluzion Posted September 29, 2008 Author Share Posted September 29, 2008 One slight issue - The same form I use to add new entries is also used to edit entries (fields are populated). I also have a delete entry button when you are in edit "mode". I'd like to be able to show a separate message for "Entry edit successful" and "Entry deleted" (in addition to the "Entry successfully added"). I thought I could do this: if (isset($_GET['edit'])) { $_SESSION['msgEdit'] = "Form edited successfully!"; } else { $_SESSION['msgAdd'] = "Form submitted successfully!"; } And: if (isset($_SESSION['msgAdd'])) { echo "<div class=\"entry_success\">" . $_SESSION['msgAdd'] . "</div>"; unset($_SESSION['msg']); } if (isset($_SESSION['msgEdit'])) { echo "<div class=\"entry_success\">" . $_SESSION['msgEdit'] . "</div>"; unset($_SESSION['msgEdit']); } But that just seems to show both messages regardless... actually, now it just seems to show the form submitted successfully all the time... hm, not sure what I screwed up. Link to comment https://forums.phpfreaks.com/topic/126361-notifying-user-on-successful-form-entry/#findComment-653476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.