Message after redirect
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Message after redirect
When a user updates his/her settings I need to have it so after it runs the update function, it redirects back to itself, making sure that the information appears updated to the user. The problem is, is that I also want to display a message that displays something like "Updated!". How do I do this?
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Message after redirect
Sounds like it would be a good idea to use the URL. Something like file.php?update=success
Then:
Then:
<?php if(isset($_GET['update']) && $_GET['update'] == "success") { echo "Updated!"; } ?>
<?php while(!$succeed = try()); ?>
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Message after redirect
Thanks! That would work but is there some other way so the user doesn't see anything "different" about the url?
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Message after redirect
You can use a url rewrite in .htaccess I believe.
Try adding this to your .htaccess Replace the two occurrences of file with your file name, excluding the extension (assuming it ends in .php, if not replace .php with .whatever)
Try adding this to your .htaccess Replace the two occurrences of file with your file name, excluding the extension (assuming it ends in .php, if not replace .php with .whatever)
Code: Select all
RewriteEngine On
RewriteRule ^file\.php$ /file.php?update=success [L]
<?php while(!$succeed = try()); ?>
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Message after redirect
OK a big problem with this is if it is updated, then the user tries to update another field, where they do something wrong and it throws an error like "Please enter a password" then the webpage reads
Updated! Error: Please enter a password *form*
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Message after redirect
It seems rewriting the URL would cause major issues with your whole updating. Major issues that would most likely take an extremely long time to work around. So, another option would probably be good using sessions. Wherever you are running the function, set a session like $_SESSION['update'] = "win"; Then back on your page:
<?php session_start(); if(isset($_SESSION['update']) && $_SESSION['update'] == "win")) { echo "Updated!"; // You want to remove the session so it doesn't have the (low) possibility of slowing down the site, and if the user returns to the page it won't show Updated! every time session_unset($_SESSION['update']); } ?>
<?php while(!$succeed = try()); ?>
Re: Message after redirect
I'm sorry, but why do you want to hide any URL changes?
It's too much work to just use htaccess and sessions.
Just stick to GET variables in the URL. It easier to understand.
It's too much work to just use htaccess and sessions.
Just stick to GET variables in the URL. It easier to understand.
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Message after redirect
I'm fine with not hiding the url but using GET alone would make it so if an error arose, it would still output that it was successfully updated.Helx wrote:I'm sorry, but why do you want to hide any URL changes?
It's too much work to just use htaccess and sessions.
Just stick to GET variables in the URL. It easier to understand.
Re: Message after redirect
Don't redirect if its not successful?FrederickGeek8 wrote:if an error arose, it would still output that it was successfully updated.
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Message after redirect
If it is first updated successfully, then it reads "Update". If the user does not change pages, then the user changes something else and does not update successfully, then ?update is still present.Helx wrote:Don't redirect if its not successful?FrederickGeek8 wrote:if an error arose, it would still output that it was successfully updated.
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Message after redirect
Why not use the form action attribute to set the form to submit to the same page? It would automatically remove the ?update from the URL
<?php while(!$succeed = try()); ?>
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: Message after redirect
... i never though of that... silly me