Menu Close
    Hire Us Request Quote Reading List Switch to Dark Mode

    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.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close