aljon ngo Posted June 4, 2014 Posted June 4, 2014 I am trying to create a custom footer module for my site, It is my first time to create a module in prestashop 1.6 and i read about this article http://doc.prestashop.com/display/PS16/Adding+a+configuration+page my problem is i cannot fully understand if i need to create a custom table for my module or not Configuration::updateValue('FOOTERCUSTOM_NAME', $footercustom); as you can see in this code, the Configuration table is already created and Configuration::updateValue is a default prestashop code if i wanted to create a input 1 , input 2 and input 3 at our configuration page in module backoffice and it automatically output the data in the database at my hookfooter. what is the proper way of doing this. note that i already succeeded in craeting a basic module, my main problem in how to insert data on my database using the configuration in my module Share this post Link to post Share on other sites More sharing options...
vekia Posted June 4, 2014 Posted June 4, 2014 hello Configuration::updateValue('FOOTERCUSTOM_NAME', $footercustom); its not a code to create "table", with this code you create new field in ps_configuration table field name will be "FOOTERCUSTOM_NAME" so if you want several inputs, use: Configuration::updateValue('FOOTERCUSTOM_NAME1', $footercustom); Configuration::updateValue('FOOTERCUSTOM_NAME2', $footercustom); Configuration::updateValue('FOOTERCUSTOM_NAME3', $footercustom); Configuration::updateValue('FOOTERCUSTOM_NAME4', $footercustom); etc.so, create fields: <input type="text" name="FOOTERCUSTOM_NAME1" value="'.Configuration::get('FOOTERCUSTOM_NAME1').'"/> <input type="text" name="FOOTERCUSTOM_NAME2" value="'.Configuration::get('FOOTERCUSTOM_NAME2').'"/> <input type="text" name="FOOTERCUSTOM_NAME3" value="'.Configuration::get('FOOTERCUSTOM_NAME3').'"/> <input type="text" name="FOOTERCUSTOM_NAME4" value="'.Configuration::get('FOOTERCUSTOM_NAME4').'"/> and to update these fields (after submit) use: Configuration::updateValue('FOOTERCUSTOM_NAME1',Tools::getValue('FOOTERCUSTOM_NAME1')); Configuration::updateValue('FOOTERCUSTOM_NAME2',Tools::getValue('FOOTERCUSTOM_NAME2')); Configuration::updateValue('FOOTERCUSTOM_NAME3',Tools::getValue('FOOTERCUSTOM_NAME3')); Configuration::updateValue('FOOTERCUSTOM_NAME4',Tools::getValue('FOOTERCUSTOM_NAME4')); 1 Share this post Link to post Share on other sites More sharing options...
aljon ngo Posted June 5, 2014 Posted June 5, 2014 (edited) how can i ahchieve this using the public function getContent() { $output = null; if (Tools::isSubmit('submit'.$this->name)) { $my_module_name = strval(Tools::getValue('MYMODULE_NAME')); if (!$my_module_name || empty($my_module_name) || !Validate::isGenericName($my_module_name)) $output .= $this->displayError($this->l('Invalid Configuration value')); else { Configuration::updateValue('MYMODULE_NAME', $my_module_name); $output .= $this->displayConfirmation($this->l('Settings updated')); } } return $output.$this->displayForm(); } public function displayForm() { // Get default language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Configuration value'), 'name' => 'MYMODULE_NAME', 'size' => 20, 'required' => true ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); $helper = new HelperForm(); // Module, token and currentIndex $helper->module = $this; $helper->name_controller = $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; // Language $helper->default_form_language = $default_lang; $helper->allow_employee_form_lang = $default_lang; // Title and toolbar $helper->title = $this->displayName; $helper->show_toolbar = true; // false -> remove toolbar $helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen. $helper->submit_action = 'submit'.$this->name; $helper->toolbar_btn = array( 'save' => array( 'desc' => $this->l('Save'), 'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name. '&token='.Tools::getAdminTokenLite('AdminModules'), ), 'back' => array( 'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'), 'desc' => $this->l('Back to list') ) ); // Load current value $helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME'); return $helper->generateForm($fields_form); } Edited June 5, 2014 by aljon ngo (see edit history) Share this post Link to post Share on other sites More sharing options...
aljon ngo Posted June 5, 2014 Posted June 5, 2014 I already found the solution, in the public function getContent() i just add Configuration::updateValue('FOOTERCUSTOM_NAME1', Tools::getValue('FOOTERCUSTOM_NAME1')); inside the if (Tools::isSubmit('submit'.$this->name)) statement and this one to show a multiple input public function displayForm() { // Get default language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Configuration value'), 'name' => 'FOOTERCUSTOM_NAME', 'size' => 20, 'required' => true ), array( 'type' => 'text', 'label' => $this->l('Link1'), 'name' => 'FOOTERCUSTOM_NAME1', ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); 1 Share this post Link to post Share on other sites More sharing options...
vekia Posted June 5, 2014 Posted June 5, 2014 thats correct can i mark this thread as solved? everything work as you expected now ? Share this post Link to post Share on other sites More sharing options...
aljon ngo Posted June 6, 2014 Posted June 6, 2014 yes this is solved, thanks vekia Share this post Link to post Share on other sites More sharing options...
pablo.pacheco Posted June 11, 2014 Posted June 11, 2014 How can i use inputs like arrays? For instance: 'input' => array( array( 'type' => 'text', 'label' => $this->l('Configuration value'), 'name' => 'MYMODULE_NAME[]', 'size' => 20, 'required' => true ), array( 'type' => 'text', 'label' => $this->l('Configuration value2'), 'name' => 'MYMODULE_NAME[]', 'size' => 20, 'required' => true ) ), Share this post Link to post Share on other sites More sharing options...
aljon ngo Posted June 14, 2014 Posted June 14, 2014 Can you explain your question further? what is your goal How can i use inputs like arrays? For instance: 'input' => array( array( 'type' => 'text', 'label' => $this->l('Configuration value'), 'name' => 'MYMODULE_NAME[]', 'size' => 20, 'required' => true ), array( 'type' => 'text', 'label' => $this->l('Configuration value2'), 'name' => 'MYMODULE_NAME[]', 'size' => 20, 'required' => true ) ), Share this post Link to post Share on other sites More sharing options...
peterke91 Posted November 11, 2014 Posted November 11, 2014 I already found the solution, in the public function getContent() i just add Configuration::updateValue('FOOTERCUSTOM_NAME1', Tools::getValue('FOOTERCUSTOM_NAME1')); inside the if (Tools::isSubmit('submit'.$this->name)) statement and this one to show a multiple input public function displayForm() { // Get default language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Configuration value'), 'name' => 'FOOTERCUSTOM_NAME', 'size' => 20, 'required' => true ), array( 'type' => 'text', 'label' => $this->l('Link1'), 'name' => 'FOOTERCUSTOM_NAME1', ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); You forgot to put these // Load current value $helper->fields_value['FOOTERCUSTOM_NAME1'] = Configuration::get('FOOTERCUSTOM_NAME1'); to see the changes. but Thanks Share this post Link to post Share on other sites More sharing options...
elzix Posted July 20, 2015 Posted July 20, 2015 I followed the thread and created a new variable: public function getContent() { $output = null; if (Tools::isSubmit('submit'.$this->name)) { Configuration::updateValue('GEOTHEME_KEY', Tools::getValue('GEOTHEME_KEY')); $output .= $this->displayConfirmation($this->l('Settings updated')); } return $output.$this->displayForm(); } public function displayForm() { // Get default language $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Settings'), ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('WebService Key'), 'name' => 'GEOTHEME_KEY', 'size' => 20, 'required' => true ) ), 'submit' => array( 'title' => $this->l('Save'), 'class' => 'button' ) ); /* more helper code */ } But I keep getting the error: Notice on line 387 in file C:\xampp\htdocs\geoPresta\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code [8] Undefined index: GEOTHEME_KEY My value is also not being saved. What am I doing wrong? Share this post Link to post Share on other sites More sharing options...
elzix Posted July 20, 2015 Posted July 20, 2015 peterke91 was right. Adding: // Load current value $helper->fields_value['GEOTHEME_KEY'] = Configuration::get('GEOTHEME_KEY'); Fixed the problem. Share this post Link to post Share on other sites More sharing options...
CS Appsaradev Posted December 10, 2015 Posted December 10, 2015 Thanks you so much, you save my time a lots. Regard. Chantouch Share this post Link to post Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now