If you are using a session model that extends the class Mage_Core_Model_Session_Abstract then you should be able to pass the value of true to the getMessages function. This will clone the messages ready to return them to be displayed to the user and then clear them from the session so they will only be displayed once.
public function getMessages($clear=false)
{
if (!$this->getData('messages')) {
$this->setMessages(Mage::getModel('core/message_collection'));
}
if ($clear) {
$messages = clone $this->getData('messages');
$this->getData('messages')->clear();
Mage::dispatchEvent('core_session_abstract_clear_messages');
return $messages;
}
return $this->getData('messages');
}
Regarding the Ajax grids
You need to:
Update thanks to the comment of Richard Parnaby-King:
I forgot to mention this: set the use_ajax property of the grid block to true:
$this->setUseAjax(true)
This can be done in the _construct()
method.
Then implement the method getGridUrl()
on your grid block to return the Ajax request URL
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current' => true));
}
Then you need to create the controller action method to process the Ajax request. It's simple, it only needs to instantiate and render the grid block. You can do that either via $this->loadLayout(false)->renderLayout()
and add the grid block via layout XML, or instantiate and render it using PHP:
$this->getResponse()->setBody(
$this->getLayout()->createBlock('my_module/adminhtml_my_grid')->toHtml()
)
Thats all. To summarize, there are three steps:
- Implement the
getGridUrl()
method
- Implement the controller grid url action
- Render (only) the grid block
Regarding the Reset Button
The reset button should trigger a page reload via the JavaScript setLocation(window.location.href)
.
It's added in the constructor of the class Mage_Adminhtml_Block_Widget_Form_Container
.
$this->_addButton('reset', array(
'label' => Mage::helper('adminhtml')->__('Reset'),
'onclick' => 'setLocation(window.location.href)',
), -1);
If it doesn't work, it's probably because some other customization of yours breaks JavaScript execution.
To simply get rid of the button you could place a $this->removeButton('reset')
into the _prepareLayout()
method of your form container.
Best Answer
The Form-Validator is defined here:
and the
VarienForm
has avalidator
and thisvalidator
has areset
method:Try this:
Add a clear button, give it suggestform_clear as id
and add this script below