0

Can any one help me why am not able to set a magento session variable with the following code.

Mage::getSingleton('core/session')->setGiftMessage("<script type='text/javascript'>jQuery('#gift_message').val();</script>"); 

If the above implementation is wrong then please tell me how can i get a value of a text area

<textarea id="gift_message" rows="2" cols="75" name="gift-message"></textarea>

and set that value in a magento session variable to use it later.

Many thanks in advance .

5

I assume that the value is sent through post as some controller.
Just add this in the controller that handles the request:

$var = Mage::app()->getRequest()->getPost('gift_message'); //$_POST['gift_message']
Mage::getSingleton('core/session')->setGiftMessage($var);

Later you should be able to get it like this:

$val = Mage::getSingleton('core/session')->getGiftMessage()

or if you want to retrieve it and remove it from session use this

$val = Mage::getSingleton('core/session')->getGiftMessage(true)
  • great explain: or if you want to retrieve it and remove it from session use this $val = Mage::getSingleton('core/session')->getGiftMessage(true) it is also for magento2 – LucScu Jun 23 '16 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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