Search code examples
phpsmartyprestashopprestashop-1.5

Prestashop 1.5 how to save custom form using hook while processing order address form


I have added custom form on order address form.

While saving order address I want to save custom form also, but it saves order address only.

Can anyone help me please?

Custom form Image


Solution

  • Here is how I've done this on my project. It's not a clean option but it's working as expecting.

    At the top of order-carrier.tpl I've added a hook:

    {hook h="checkCustomForm"}
    

    I've created a module /mdoules/customform/customform.php

    <?php
    
    if (!defined('_PS_VERSION_'))
        exit;
    
    class CustomForm extends Module
    {
        public function __construct()
        {
            $this->name = 'customform';
            $this->tab = 'administration';
            $this->version = '1.0.0';
            $this->author = 'Florian Lemaitre';
            $this->need_instance = 0;
    
            $this->bootstrap = true;
            parent::__construct();
    
            $this->displayName = $this->l('Custom Form');
            $this->description = $this->l('Custom Form');
        }
    
        public function install()
        {
            return $this->createTable()
                && parent::install()
                && $this->registerHook('checkCustomForm');
        }
    
        public function hookcheckCustomForm($params)
        {
    
            [process your form values here (Tools::getValue('my_value') ...)]
    
            if (error)
            {
                // We redirect to the Adrress page with a flag 'missing_value' to alert an error
                Tools::redirect('index.php?controller=order&step=1&missing_value=true');
            }
        }
    }