spinelle Posted April 28, 2017 Share Posted April 28, 2017 (edited) Hi, 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 1.7.1.1 Thanks. Edited April 28, 2017 by spinelle (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted April 28, 2017 Share Posted April 28, 2017 have you tried to add an element to $this->errors variable? $this->errors[]=$this->l('something wrong blabla'); Link to comment Share on other sites More sharing options...
spinelle Posted April 28, 2017 Author Share Posted April 28, 2017 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. 1 Link to comment Share on other sites More sharing options...
-Weak- Posted May 17, 2017 Share Posted May 17, 2017 Hi, I am facing the same problem.. Did you find the trick to achieve this ? Thanks Link to comment Share on other sites More sharing options...
spinelle Posted May 18, 2017 Author Share Posted May 18, 2017 Hi, No, still nothing... Link to comment Share on other sites More sharing options...
2ltodeath Posted January 25, 2018 Share Posted January 25, 2018 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. 1 1 Link to comment Share on other sites More sharing options...
Kogkalidis Posted May 7, 2020 Share Posted May 7, 2020 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 Link to comment Share on other sites More sharing options...
ccristian Posted July 5, 2023 Share Posted July 5, 2023 I have some errors in the error log files under public_html > error_log file. Can someone have any idea on how to fix this? [04-Jul-2023 10:29:02 Europe/Bucharest] PHP Deprecated: Invalid characters passed for attempted conversion, these have been ignored in /home/myshop/public_html/classes/Tools.php on line 2408 [04-Jul-2023 10:29:02 Europe/Bucharest] PHP Deprecated: Invalid characters passed for attempted conversion, these have been ignored in /home/myshop/public_html/classes/Tools.php on line 2409 and these errors from php-ps-info-1.1 > error_log [04-Jul-2023 03:27:47 UTC] PHP Notice: Trying to access array offset on value of type int in /home/myshop/public_html/php-ps-info-1.1/phppsinfo.php on line 364 the lines of code the error_logs are pointing too are these (see the pictures attached): PrestaShop 1.7.8.9, PHP 7.4.3, Wareehouse theme (latest version) Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now