marktomm90 Posted April 19, 2014 Share Posted April 19, 2014 Hi, I have read prestashops' docs and searched the internet and couldn't find the answer. The prestashop tutorial on making a custom module shows how to change one value in module configuration menu. I am trying to make a <selection multiple="multiple"> type form to select multiple items from it and store them in a variable (DC_CATEGORIES) for later use. Unfortunately I am unable to accomplish this. Here is my code public function getContent() { $output = null; if (Tools::isSubmit('submit'.$this->name)) { $my_module_name = array(); $my_module_name = unserialize(base64_decode(Tools::getValue('DC_CATEGORIES'))); if (!$my_module_name || empty($my_module_name)) $output .= $this->displayError( $this->l('Invalid Configuration value'.$my_module_name) ); else { Configuration::updateValue('DC_CATEGORIES', base64_encode(serialize($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'); $categoriesData = Category::getCategories( 0, true, false ); $categories = array(); foreach($categoriesData as $category) { array_push($categories, array( 'id_option' => $category['id_category'], 'name' => $category['name'] )); } // Init Fields form array $fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('Settings') ), 'input' => array( array( 'type' => 'select', 'label' => $this->l('Set Categories'), 'name' => 'DC_CATEGORIES', 'multiple' => 'multiple', 'options' => array( 'query' => $categories, 'id' => 'id_option', 'name' => 'name' ) ) ), '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['DC_CATEGORIES'] = Configuration::get('DC_CATEGORIES'); return $helper->generateForm($fields_form); } I tryed using base64_encode/decode because otherwise I would get the 'Error at offset' error (http://davidwalsh.name/php-serialize-unserialize-issues) Thanks in advance. Link to comment 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