How display success a message after submit the form.
This is my site a link
Magento – How display success message after submit the form
customerformshelpermagento-1.8messages
customerformshelpermagento-1.8messages
How display success a message after submit the form.
This is my site a link
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
This is inside the app/design/frontend/base/default/template/contacts/form.phtml
So the messages are just echo'ed
twice. Either remove the standard message block from the layout or remove the above from the template. I think editing the template is easier.
Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess');
to Element.show('formSuccess2');
and added the div like this <div id="formSuccess2" style="display:none">hello</div>
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess2');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
Best Answer
In php this type of work implement on session variable.
Magento is doing by
set
success message
using->addSuccess('YOUR MSG');
.and set
error message
using->addError('YOUR ERROR MSG')
Those magento functions are Object of
Mage::getSingleton('core/session'
)Mage::getSingleton('customer/session')
Mage::getSingleton('catalog/session')
So you can set this message.
Mage::getSingleton('core/session')->addSuccess('YOUR MSG');
Mage::getSingleton('customer/session')->addSuccess('YOUR MSG');
etc
This message is shown at phtml file using add below code:
Most Important Note:
This session message
is one available up to one render
.ON Message
display page
,you need toinitialized
this session using codeinitLayoutMessages()
and you need add this code before$this->renderLayout();
function i.e Start of render layoutJust like:
Suppose you have set message at
Mage::getSingleton('customer/session')
and on message display page you have not initialized$this->_initLayoutMessages('customer/session');
Then you did not get this message.
A Good example is contact page:
Message is show at
indexAction
: