Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

Display Custom Error On Symfony Admin Product Controller Form In Prestashop 1.7

In this post, I am going to explain how we can display the error on Admin Product controller custom form in our module.

Step 1:-  Changes in template form

Register the hook displayProductExtra and return the HTML

Make sure you have added id=”form_hooks_{field_name}” in the form field where you want to display the error.

<input type=”text” name=”{field_name}” id=”form_hooks_{field_name}” />

Example:-

<input type=”text” name=”title” id=”form_hooks_title” />

Step 2:- On Product Save

Inside ActionProductSave hook check the condition and set the error in the following format

$this->context->controller->errors['hooks_{form_field_name}'] = array('{Error Message}'));

Example: –

$this->context->controller->errors['hooks_title'] = array('Invalid Input'));

Now check the condition whether there is an error or not.

If there is an error then set the http_response_code with 400 and die the error.

if ($this->context->controller->errors) {
    http_response_code(400);
    die(json_encode($this->context->controller->errors));
}

This is how we can display the error message in the Admin Product controller custom form of our module.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home