Jump to content

HelperForm hidden input field value


Recommended Posts

Dummy question but I cannot seem to find a straightforward answer. I am building a form using the HelperForm class and I want to pass a hidden field with it for which I use:

			'type' => 'hidden',
			'value' => 43,
			'name' => 'id_product'

Where value seems to invalid key in the array and doesn`t work. I saw the values array but it is said that it is used for radio buttons only.


How am I suppose to assign value to the input field?


EDIT: Found the solution myself. Inserted this when configuring the helper:

$helper->fields_value['id_product'] = Tools::getValue('id_product');
Edited by GS VISION (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 5 years later...

Hi GS,

I know your post is old but i'm stucked at this point on PS 1.7.6, I built my config form with an hidden field and I cannot find the way to assign him the default value. I tried to add the configuration to the helper but still no success. Do you have any suggestion?



Link to comment
Share on other sites

something like that: (replace yourmodule/YOUR_MODULE_.. with your names)

public function switchYesNo($switchName) {
        return  array(
                'id' => $switchName .'_1',
                'value' => 1,
                'label' => $this->module->l('Enabled')
                'id' => $switchName.'_0',
                'value' => 0,
                'label' => $this->module->l('Disabled')

public function processConfiguration()
        if (Tools::isSubmit('yourmodule_form'))
            Configuration::updateValue('YOUR_MODULE_VAR1',Tools::getValue('YOUR_MODULE_VAR1',''));     //text
            Configuration::updateValue('YOUR_MODULE_VAR2',(int)Tools::getValue('YOUR_MODULE_VAR1',0));  //switch
            // if you want store default value of hidden field then

            $this->context->smarty->assign('confirmation', 'ok');            


public function renderYourModuleConfigForm()
        $inputs = array(
            array('name' => 'YOUR_MODULE_VAR1', 'label' => $this->module->l('variable1'), 'type' => 'text'),
            array('name' => 'YOUR_MODULE_VAR2', 'label' => $this->module->l('variable2'), , 'type' => 'switch', 'values' => $this->switchYesNo('YOUR_MODULE_VAR2')),
            array('name' => 'YOUR_MODULE_VAR3',  'type' => 'hidden'),
//          ...

        $fields_form = array(
            'form' => array(
                'legend' => array(
                    'title' => $this->module->l('Your title'),
                    'icon' => 'icon-wrench'
                'input' => $inputs,
                'submit' => array('title' => $this->module->l('Save'))

        $helper = new HelperForm();
        $helper->table = 'yourmodule';
        $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
        $helper->allow_employee_form_lang = (int)Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG');
        $helper->submit_action = 'yourmodule_form';
        $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->module->name.'&tab_module='.$this->module->tab.'&module_name='.$this->module->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->fields_value = array(
            'YOUR_MODULE_VAR1' => Tools::getValue('YOUR_MODULE_VAR1', Configuration::get('YOUR_MODULE_VAR1')),
            'YOUR_MODULE_VAR2' => Tools::getValue('YOUR_MODULE_VAR2', Configuration::get('YOUR_MODULE_VAR2')),
            'YOUR_MODULE_VAR3' => (Configuration::get('YOUR_MODULE_VAR3')) ? Configuration::get('YOUR_MODULE_VAR3') : DEFAULT_VALUE_OF_VAR3,
//        ....
            $helper->tpl_vars = array(
            'fields_value' => $helper->fields_value,
            'languages' => $this->context->controller->getLanguages()

        return $helper->generateForm(array($fields_form));

public function getContent()
        $html_form = $this->renderYourModuleConfigForm();
        $this->context->smarty->assign('form', $html_form);
        $html = $this->module->display($this->file, 'getContent.tpl');
        return $html;


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