2

I have a custom module which involves the user submitting a form to an external URL then being redirected to the page on my site from which they submitted the form, with the idea that they are shown the success feedback message and can continue from where they left off. Given that the URL the user can be redirected to is any URL on the site, I think I need to add some form of helper class to my module which checks all URLs for the relevant query string, then adds the success message into the page template.

I'm fairly new to magento so how I actually do this via a helper class in my module, I'm not entirely sure - and also then how the helper should interact the template to show the success message. Grateful if anyone could point me in the right direction? Old school way to do it would be just to check for the query string in the main template used by all pages on the site, but I realise that would be bad practice!

1 Answer 1

5

You can check for the parameter in a variety of places, but you might want to do this in the template that will load the block in question:

   <?php if (isset(Mage::app()->getRequest()->getParam('your_param'))) : ?>
       <?php echo $this->getChildHtml('your_block') ?>
   <?php endif; ?>

Since you want to check every request that comes in, if you placed this inside a controller you would only be checking the request that hit a certain URL (unless you rewrote things).

If you would rather clean up the template with a helper function, you could do something like:

   <?php if ($yourHelper->checkRequest()) : ?>
       <?php echo $this->getChildHtml('your_block') ?>
   <?php endif; ?>

...and then in your helper class' checkRequest() method:

$request = Mage::app()->getRequest();
if (!isset($request->getParam('your_param'))) {
    return false;
}
return true;

You can access request variables by using these methods:

Mage::app()->getRequest()->getPost('your_param'); // pass key value or leave empty for all $_POST
Mage::app()->getRequest()->getParam('your_param'); // Get's a param by key, $_GET or $_POST
Mage::app()->getRequest()->getQuery('your_param'); // Same as getPost() but for $_GET
Mage::app()->getRequest()->getParams(); // Gets everything, $_GET and $_POST

See lib/Zend/Controller/Request/Http.php for additional methods available.


6
  • Thanks pspahn, but my issue isn't how to specifically get the parameters, but how this should be handled within a magento module, where the responsibility should lie - i.e as i want every URL to be checked, should i use the default handle (in my custom module's config.xml) to pass all URLs to a helper class, which would then set a session variable for example if the query string existed, which the view template could access.
    – tomh545
    Oct 29, 2013 at 23:52
  • You need to check the user's URL, and if a certain parameter is there with a certain value, then load up a specific block? Is that right?
    – pspahn
    Oct 29, 2013 at 23:55
  • Yeah the URL could be anything on the site, so I need to check every URL for the param and conditionally load a success message block.
    – tomh545
    Oct 29, 2013 at 23:59
  • See edited answer.
    – pspahn
    Oct 30, 2013 at 0:13
  • I think I was over-complicating it and thinking I had to handle that conditional logic completely outside of the template - but I think it's probably inevitable that there has to be a condition there, and your example with the helper would be the route i'd go down. Many thanks!
    – tomh545
    Oct 30, 2013 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.