Jump to content

Display an error message from a module in product admin

Recommended Posts



I have a module in the admin product form (hookDisplayAdminProductsExtra) with a form that should alway be complete by the user, when he add a new product.


I would like to display the error message when a field is empty or not valid, exactly the same way the fields of the product form does. I've been looking in this file "\vendor\symfony\symfony\src\Symfony\Component\Form\Form.php" but I'm not sur how I can do...


I have a Prestashop



Edited by spinelle (see edit history)

Share this post

Link to post
Share on other sites
  • 3 weeks later...
  • 8 months later...

I found a solution.

First, In your hook you must set 

header("HTTP/1.0 400 Bad Request");

After this, the error message will appear at the top-right side of the screen (predefined error message of the Prestashop).

You can show your custom error message only if you have some tpl file in your module. This file must contain an element, to which the error message will be attached. It can be both input or any other HTML element.

In my example I have table. You should give it an id that must starts with "form_". E.g.:

<table class="table" id="form_some_id">

Then, in your PHP file (after the header been set) you should return an error in this format:

die(json_encode(array('some_id' => array($this->l('Error text.')))));

Note, that structure must be as in example. Key of the array should be as ID of the element, but without "form_".
The text of an error will be shown after the element.

Hope this will help somebody.

  • Thanks 1

Share this post

Link to post
Share on other sites
  • 2 years later...
On 4/28/2017 at 5:01 PM, spinelle said:

Thank you for your answer.


Yes I did try that. I also tried: $this->context->controller->errors[] = $this->l('My error');

But none of them worked.

This worked for me. I code a module for a client of mine (1.6.0.x version) and this solved my hands. Thanx

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More