Jump to content

Help with postprocess on controller


Recommended Posts


I am able to capture the postprocess for adding a new item (submitAddcustom_notes_templates). I cannot figure out how to do it after an item is edited. I tried submitEditcustom_notes_templates without success. Here is the code.

public function postProcess()
	{
		
		if (Tools::isSubmit('submitAddcustom_notes_templates')) 
		{
                       $message = 'test1';
                }
		else if(Tools::isSubmit('submitEditcustom_notes_templates'))
		{
			$message = 'test2';
		}
		echo "<script type='text/javascript'>alert('$message');</script>";
		parent::postProcess();
	} 

Link to comment
Share on other sites

It seems that there is some error in the code that you have added. The following line:

 

echo "<script type='text/javascript'>alert('$message');</script>";

 

has to be something like this

 

echo "<script type='text/javascript'>alert(".$message.");</script>";

 

If this is doesn't solves the problem, can you please tell us what issue you are facing exactly and what are you trying to achieve?

Link to comment
Share on other sites

Thanks for the reply Knowband. The popup code works fine. I use it all the time for debugging. I get popup 'test1' when adding new items with my controller. My problem is when I edit an item. I do not get 'test1' (nor 'test2' but I just tried submitEditcustom_notes_templates  for the heck of it). The button on the form has the same name: submitAddcustom_notes_templates. What I dont understand is how the controller differentiates an edit from an add. I need to do something post process after an item is edited. 

Edited by belyza (see edit history)
Link to comment
Share on other sites

They both passed under the same submitAddcustom_notes_templates. My problem was further down the line. I ended using this code to determine if it was an Add (for new item) or Edit (of an existing item):

public function initProcess()
{
	if (Tools::isSubmit('submitAddcustom_notes_templates')) 
	{
                parent::validateRules();
                if (count($this->errors))
                        return false;
                if (!$id_custom_notes_templates = (int) Tools::getValue('id_custom_notes_templates')) 
			/*do something after add*/			
		else
			/*do something after edit*/
        }
	parent::initProcess();
} 
Edited by belyza (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...