Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Modifying $_GET

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
boyer
Smarty Rookie


Joined: 08 Apr 2009
Posts: 9

PostPosted: Wed Nov 24, 2010 5:09 am    Post subject: Modifying $_GET Reply with quote

Hey everyone!

I'm sure there's a simple way to accomplish what I'm looking to do here, and I'm just missing it...

Let's say I have a controller class that extends Smarty, and does all my work for me. At the end of the controllers work, it calls $this->display('myTemplate.tpl'); and we're off to the browser.

Let's say I've got an email inbox, and I've just made a GET request to delete message #999. I pass the parms like this: inbox.php?action=delete&messageId=999.

My controller does it's thing, deletes the message, gets the messages from the db, then displays them back to the user. The problem is, I still have "&action=delete&messageId=999" in the URL bar. If the user refreshes, they'll get an error message stating that message doesn't exist etc etc.

Is there any easy way in Smarty to remove those parameters from GET?
I've tried doing it directly in php before I call $this->display() by doing $_GET["action'] = "" or unset($_GET["action"]) or $_GET["action"] = null, but none of these things do what I need them to.

I really don't want to resort to doing all my actions via POST (means adding more javascript).

Thanks for the help!
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Wed Nov 24, 2010 9:53 am    Post subject: Reply with quote

Have you tried to explode() the url with "?" and redirect to "new" URI ?
Back to top
View user's profile Send private message
boyer
Smarty Rookie


Joined: 08 Apr 2009
Posts: 9

PostPosted: Wed Nov 24, 2010 5:36 pm    Post subject: Reply with quote

Well atcuall I already have some convenience methods written to take the get args I currently have, add/remove/modify them, then build out the new string that would be appended to the URI.

Trouble is, I need my template output to display. I don't want to redirect to another controller first.

Can you think of a usage example where at the end of my controller, but before I call $this->display() that I could implement this?
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Mon Nov 29, 2010 12:15 am    Post subject: Reply with quote

I don't think you want to modify the $_GET array (at the server), because that would not change the fact that when the user presses refresh (at the client) the browser will request the same page as last time. You will have to forward them to a new page either using this:

http://php.net/manual/en/function.header.php

or this:

http://www.tizag.com/javascriptT/javascriptredirect.php

You could redirect to a generic "Your message has been deleted" page.

But, the real problem is that those types of non-repeatable requests should not be made using GET they should be made using POST.

http://www.cs.tut.fi/~jkorpela/forms/methods.html#why
Back to top
View user's profile Send private message
creiglee
Smarty n00b


Joined: 16 Jul 2015
Posts: 1

PostPosted: Thu Jul 16, 2015 7:21 am    Post subject: Reply with quote

Try use...Jacascript Redirect

Lee
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP