prestashop_newuser Posted March 8, 2014 Share Posted March 8, 2014 Hi, I just installed prestashop 1.6 on my localhost and tried to make a module. So in module I just used a form . So for craeting form I tried this code public function renderForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('My ModuleSettings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Site Url'), 'name' => 'YOUR_NAME', 'desc' => $this->l('Enter Your Name'), 'lang' => true, ), array( 'type' => 'select', 'lang' => true, 'label' => $this->l('Link Target'), 'name' => 'WEBSITE_LINK_TARGET', 'desc' => $this->l('Please Eneter Web Site URL Address.'), 'options' => array( 'query' => $options, 'id' => 'id_option', 'name' => 'name' ), $options = array( array( 'id_option' => 1, 'name' => 'Method 1' ), array( 'id_option' => 2, 'name' => 'Method 2' ), ) ), 'submit' => array( 'title' => $this->l('Save') ) ), ); $helper = new HelperForm(); $helper->show_toolbar = true; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->module = $this; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'submitmymoduleconf'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'uri' => $this->getPathUri(), 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } But this code is not showing the select options input fields in the form. Whenever I am trying to load the page it is showing error like Undefined variable: options. I have gone through the documentation from this link http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class but still can't able to solve this issue. So if someone kindly help me to solve this I will be really appreciable. Thanks. Link to comment Share on other sites More sharing options...
prestashop_newuser Posted March 10, 2014 Author Share Posted March 10, 2014 Hi, I just installed prestashop 1.6 on my localhost and tried to make a module. So in module I just used a form . So for craeting form I tried this code public function renderForm() { $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('My ModuleSettings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Site Url'), 'name' => 'YOUR_NAME', 'desc' => $this->l('Enter Your Name'), 'lang' => true, ), array( 'type' => 'select', 'lang' => true, 'label' => $this->l('Link Target'), 'name' => 'WEBSITE_LINK_TARGET', 'desc' => $this->l('Please Eneter Web Site URL Address.'), 'options' => array( 'query' => $options, 'id' => 'id_option', 'name' => 'name' ), $options = array( array( 'id_option' => 1, 'name' => 'Method 1' ), array( 'id_option' => 2, 'name' => 'Method 2' ), ) ), 'submit' => array( 'title' => $this->l('Save') ) ), ); $helper = new HelperForm(); $helper->show_toolbar = true; $helper->table = $this->table; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->module = $this; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = $this->identifier; $helper->submit_action = 'submitmymoduleconf'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'uri' => $this->getPathUri(), 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } But this code is not showing the select options input fields in the form. Whenever I am trying to load the page it is showing error like Undefined variable: options. I have gone through the documentation from this link http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class but still can't able to solve this issue. So if someone kindly help me to solve this I will be really appreciable. Thanks. Hello, Any solution out there? Link to comment Share on other sites More sharing options...
astragor Posted March 10, 2014 Share Posted March 10, 2014 I think you should post in english forum ! Link to comment Share on other sites More sharing options...
Nighthawk85 Posted July 25, 2014 Share Posted July 25, 2014 You should try the following : public function renderForm() { $options = array( array( 'id_option' => 1, 'name' => 'Method 1' ), array( 'id_option' => 2, 'name' => 'Method 2' ), ); $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('My ModuleSettings'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Site Url'), 'name' => 'YOUR_NAME', 'desc' => $this->l('Enter Your Name'), 'lang' => true, ), array( 'type' => 'select', 'lang' => true, 'label' => $this->l('Link Target'), 'name' => 'WEBSITE_LINK_TARGET', 'desc' => $this->l('Please Eneter Web Site URL Address.'), 'options' => array( 'query' => $options, 'id' => 'id_option', 'name' => 'name' ) ), 'submit' => array( 'title' => $this->l('Save') ) ), ); 1 Link to comment Share on other sites More sharing options...
Oron Posted July 26, 2014 Share Posted July 26, 2014 Bonjour Here French Forum. Topic moved to English Forum http://www.prestashop.com/forums/forum/242-new-prestashop-16/ Link to comment Share on other sites More sharing options...
duazo_joesel Posted February 11, 2015 Share Posted February 11, 2015 (edited) I got that problem earlier too and got the solution try this code array( 'type' => 'select', 'label' => $this->l('Category:'), 'name' => 'category', 'required' => true, 'options' => array( 'query' => $options = array( array( 'id_option' => 1, // The value of the 'value' attribute of the <option> tag. 'name' => 'Method 1' // The value of the text content of the <option> tag. ), array( 'id_option' => 2, 'name' => 'Method 2' ), ), 'id' => 'id_option', 'name' => 'name' ) ) Edited February 11, 2015 by duazo_joesel (see edit history) 3 Link to comment Share on other sites More sharing options...
Recommended Posts