Hello everybody I've made an override of Prestashop Customers object form to edit the customer's id from backend. I rendere all the fields with no problem but when I push sabe button it gives me error... I will paste my code below.
<?php
Class AdminCustomersController extends AdminCustomersControllerCore{
public function renderForm(){
/** #var Customer $obj */
if (!($obj = $this->loadObject(true))) {return;}
$genders = Gender::getGenders();
$list_genders = array();
foreach ($genders as $key => $gender) {
/** #var Gender $gender */
$list_genders[$key]['id'] = 'gender_'.$gender->id;
$list_genders[$key]['value'] = $gender->id;
$list_genders[$key]['label'] = $gender->name;
}
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
$groups = Group::getGroups($this->default_form_language, true);
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Customer'),
'icon' => 'icon-user'
),
'input' => array(
array(
'type' => 'text', // id_customer field to edit
'label' => $this->l('Codice cliente'),
'name' => 'id_customer',
'size' => 64,
'col' => '4'
),
array(
'type' => 'radio',
'label' => $this->l('Social title'),
'name' => 'id_gender',
'required' => false,
'class' => 't',
'values' => $list_genders
),
array(
'type' => 'text',
'label' => $this->l('First name'),
'name' => 'firstname',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Last name'),
'name' => 'lastname',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Codice cliente Target:'),
'name' => 'codice_target',
'size' => 64,
'col' => '4'
),
array(
'type' => 'text',
'label' => $this->l('Company'),
'name' => 'company',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('P.iva'),
'name' => 'vat_number',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'prefix' => '<i class="icon-envelope-o"></i>',
'label' => $this->l('Email address'),
'name' => 'email',
'col' => '4',
'required' => true,
'autocomplete' => false
),
array(
'type' => 'password',
'label' => $this->l('Password'),
'name' => 'passwd',
'required' => ($obj->id ? false : true),
'col' => '4',
'hint' => ($obj->id ? $this->l('Leave this field blank if there\'s no change.') :
sprintf($this->l('Password should be at least %s characters long.'), Validate::PASSWORD_LENGTH))
),
/*array(
'type' => 'birthday',
'label' => $this->l('Birthday'),
'name' => 'birthday',
'options' => array(
'days' => $days,
'months' => $months,
'years' => $years
)
),*/
array(
'type' => 'switch',
'label' => $this->l('Enabled'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'hint' => $this->l('Enable or disable customer login.')
),
array(
'type' => 'switch',
'label' => $this->l('Newsletter'),
'name' => 'newsletter',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'newsletter_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'newsletter_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'disabled' => (bool)!Configuration::get('PS_CUSTOMER_NWSL'),
'hint' => $this->l('This customer will receive your newsletter via email.')
),
array(
'type' => 'switch',
'label' => $this->l('Opt-in'),
'name' => 'optin',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'optin_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'optin_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'disabled' => (bool)!Configuration::get('PS_CUSTOMER_OPTIN'),
'hint' => $this->l('This customer will receive your ads via email.')
),
)
);
// if we add a customer via fancybox (ajax), it's a customer and he doesn't need to be added to the visitor and guest groups
if(Tools::isSubmit('addcustomer') && Tools::isSubmit('submitFormAjax')){
$visitor_group = Configuration::get('PS_UNIDENTIFIED_GROUP');
$guest_group = Configuration::get('PS_GUEST_GROUP');
foreach ($groups as $key => $g) {
if (in_array($g['id_group'], array($visitor_group, $guest_group))) {
unset($groups[$key]);
}
}
}
$this->fields_form['input'] = array_merge(
$this->fields_form['input'],
array(
array(
'type' => 'group',
'label' => $this->l('Group access'),
'name' => 'groupBox',
'values' => $groups,
'required' => true,
'col' => '6',
'hint' => $this->l('Select all the groups that you would like to apply to this customer.')
),
array(
'type' => 'select',
'label' => $this->l('Default customer group'),
'name' => 'id_default_group',
'options' => array(
'query' => $groups,
'id' => 'id_group',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('This group will be the user\'s default group.'),
$this->l('Only the discount for the selected group will be applied to this customer.')
)
)
)
);
// if customer is a guest customer, password hasn't to be there
if ($obj->id && ($obj->is_guest && $obj->id_default_group == Configuration::get('PS_GUEST_GROUP'))) {
foreach ($this->fields_form['input'] as $k => $field) {
if ($field['type'] == 'password') {
array_splice($this->fields_form['input'], $k, 1);
}
}
}
if(Configuration::get('PS_B2B_ENABLE')) {
$risks = Risk::getRisks();
$list_risks = array();
foreach ($risks as $key => $risk) {
/** #var Risk $risk */
$list_risks[$key]['id_risk'] = (int)$risk->id;
$list_risks[$key]['name'] = $risk->name;
}
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Company'),
'name' => 'company'
);
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('SIRET'),
'name' => 'siret'
);
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('APE'),
'name' => 'ape'
);
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Website'),
'name' => 'website'
);
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Allowed outstanding amount'),
'name' => 'outstanding_allow_amount',
'hint' => $this->l('Valid characters:').' 0-9',
'suffix' => $this->context->currency->sign
);
$this->fields_form['input'][] = array(
'type' => 'text',
'label' => $this->l('Maximum number of payment days'),
'name' => 'max_payment_days',
'hint' => $this->l('Valid characters:').' 0-9'
);
$this->fields_form['input'][] = array(
'type' => 'select',
'label' => $this->l('Risk rating'),
'name' => 'id_risk',
'required' => false,
'class' => 't',
'options' => array(
'query' => $list_risks,
'id' => 'id_risk',
'name' => 'name'
),
);
}
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
);
$birthday = explode('-', $this->getFieldValue($obj, 'birthday'));
$this->fields_value = array(
'years' => $this->getFieldValue($obj, 'birthday') ? $birthday[0] : 0,
'months' => $this->getFieldValue($obj, 'birthday') ? $birthday[1] : 0,
'days' => $this->getFieldValue($obj, 'birthday') ? $birthday[2] : 0,
);
// Added values of object Group
if (!Validate::isUnsignedId($obj->id)) {
$customer_groups = array();
}
else {
$customer_groups = $obj->getGroups();
}
$customer_groups_ids = array();
if (is_array($customer_groups)) {
foreach ($customer_groups as $customer_group) {
$customer_groups_ids[] = $customer_group;
}
}
// if empty $carrier_groups_ids : object creation : we set the default groups
if (empty($customer_groups_ids)) {
$preselected = array(
Configuration::get('PS_UNIDENTIFIED_GROUP'),
Configuration::get('PS_GUEST_GROUP'),
Configuration::get('PS_CUSTOMER_GROUP')
);
$customer_groups_ids = array_merge($customer_groups_ids, $preselected);
}
foreach ($groups as $group) {
$this->fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], in_array($group['id_group'], $customer_groups_ids));
}
return AdminController::renderForm();
}
}
?>
Many thanks
Related
How to add hidden values or insert values to fields that are not exposed to user such as date_add and date_upd when Using the HelperForm class in PRESTASHOP 1.6.3
I created a new module and now there are two fields in my table which need to be inserted when a new add happens and when an update is done by the user but how to do this when I am using HelperForm class in PRESTASHOP
Below is my render form script
// This form is populated when add or edit is clicked
public function renderForm()
{
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
$ticketSeries = Winners::getTicketSeries();
$prdtCategory = Winners::getProductCategory();
$nationality = Winners::getNationality();
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Configure your Winner'),
'icon' => 'icon-user'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Ticket No'),
'name' => 'ticket_no',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
),
array(
'type' => 'select',
'label' => $this->l('Ticket Series'),
'name' => 'series',
'required' => true,
'options' => array(
'query' => $ticketSeries,
'id' => 'ticket_series_name',
'name' => 'ticket_series_name'
),
'col' => '4',
'hint' => array(
$this->l('The ticket series of each draw !!.')
)
),
array(
'type' => 'select',
'label' => $this->l('Category'),
'name' => 'category',
'required' => true,
'options' => array(
'query' => $prdtCategory,
'id' => 'name',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('Product Category.')
)
),
array(
'type' => 'date',
'label' => $this->l('Draw Date:'),
'name' => 'draw_date',
'size' => 10,
'required' => true,
'desc' => $this->l('The draw date of this series'),
),
array(
'type' => 'select',
'label' => $this->l('Nationality'),
'name' => 'nationality',
'required' => true,
'options' => array(
'query' => $nationality,
'id' => 'name',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('Nationality the winner Belongs .')
)
),
array(
'type' => 'textarea',
'label' => $this->l('Testimonial'),
'name' => 'testimonial',
'required' => true,
'autoload_rte' => true,
'rows' => 7,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
), // add tag 'autoload_rte' => true, 'lang' => true, --> lang i removed
// since the editor value did not submit editor
)
);
//d(Tools::getIsset('update'));
if (Tools::getIsset('add') )
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
))
));
if (Tools::getIsset('update'))
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;? =+()##"°{}_$%:'
))
));
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
);
$this->addJqueryUI('ui.datepicker');
return parent::renderForm();
}
I tried something like below yet no use
if (Tools::getIsset('add') )
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()##"°{}_$%:'
))
));
if (Tools::getIsset('update'))
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;? =+()##"°{}_$%:'
))
));
use 'type' => 'hidden' and provide the value with, for example, 'value' => date("Y-m-d H:i:s")
I have a backend-problem with Typo3 6.2 and my tt_address extended fields:
In Typo3 4.5 I extended the tt_address database-fields with a little extension built with kickstarter. After the update to Typo3 6.2 these fields disappeared in the backend so I can't edit them anymore.
In the Frontend everything is fine, all fields are there.
Any idea, how I can access these fields again in the backend?
Here's the content of my ext_tables.php:
if (!defined('TYPO3_MODE')) { die ('Access denied.'); }
$tempColumns = array (
'tx_ttaddressextended_kuerzel' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_kuerzel',
'config' => array (
'type' => 'input',
'size' => '30',
'max' => '2',
)
),
'tx_ttaddressextended_kurzwahl' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_kurzwahl',
'config' => array (
'type' => 'input',
'size' => '30',
)
),
'tx_ttaddressextended_by_tema' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_by_tema',
'config' => array (
'type' => 'input',
'size' => '30',
)
),
'tx_ttaddressextended_ausbildung' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_ausbildung',
'config' => array (
'type' => 'text',
'cols' => '30',
'rows' => '5',
'wizards' => array(
'_PADDING' => 2,
'RTE' => array(
'notNewRecords' => 1,
'RTEonly' => 1,
'type' => 'script',
'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
'icon' => 'wizard_rte2.gif',
'script' => 'wizard_rte.php',
),
),
)
),
'tx_ttaddressextended_abschluss' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_abschluss',
'config' => array (
'type' => 'input',
'size' => '30',
)
),
'tx_ttaddressextended_sprachen' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_sprachen',
'config' => array (
'type' => 'input',
'size' => '30',
)
),
'tx_ttaddressextended_laufbahn' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_laufbahn',
'config' => array (
'type' => 'text',
'cols' => '30',
'rows' => '5',
'wizards' => array(
'_PADDING' => 2,
'RTE' => array(
'notNewRecords' => 1,
'RTEonly' => 1,
'type' => 'script',
'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
'icon' => 'wizard_rte2.gif',
'script' => 'wizard_rte.php',
),
),
)
),
'tx_ttaddressextended_auszeichnungen' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_auszeichnungen',
'config' => array (
'type' => 'text',
'cols' => '30',
'rows' => '5',
'wizards' => array(
'_PADDING' => 2,
'RTE' => array(
'notNewRecords' => 1,
'RTEonly' => 1,
'type' => 'script',
'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
'icon' => 'wizard_rte2.gif',
'script' => 'wizard_rte.php',
),
),
)
),
'tx_ttaddressextended_besondere_projekte' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_besondere_projekte',
'config' => array (
'type' => 'text',
'cols' => '30',
'rows' => '5',
'wizards' => array(
'_PADDING' => 2,
'RTE' => array(
'notNewRecords' => 1,
'RTEonly' => 1,
'type' => 'script',
'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
'icon' => 'wizard_rte2.gif',
'script' => 'wizard_rte.php',
),
),
)
),
'tx_ttaddressextended_aktiv' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_aktiv',
'config' => array (
'type' => 'text',
'cols' => '30',
'rows' => '5',
'wizards' => array(
'_PADDING' => 2,
'RTE' => array(
'notNewRecords' => 1,
'RTEonly' => 1,
'type' => 'script',
'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
'icon' => 'wizard_rte2.gif',
'script' => 'wizard_rte.php',
),
),
)
),
'tx_ttaddressextended_interessen' => array (
'exclude' => 0,
'label' => 'LLL:EXT:tt_address_extended/locallang_db.xml:tt_address.tx_ttaddressextended_interessen',
'config' => array (
'type' => 'text',
'cols' => '30',
'rows' => '5',
'wizards' => array(
'_PADDING' => 2,
'RTE' => array(
'notNewRecords' => 1,
'RTEonly' => 1,
'type' => 'script',
'title' => 'Full screen Rich Text Editing|Formatteret redigering i hele vinduet',
'icon' => 'wizard_rte2.gif',
'script' => 'wizard_rte.php',
),
),
)
),
);
//t3lib_div::loadTCA('tt_address');
if (version_compare(TYPO3_branch, '6.1', '<')) {
t3lib_div::loadTCA('tt_content');
}
t3lib_extMgm::addTCAcolumns('tt_address',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('tt_address',
'tx_ttaddressextended_kuerzel;;;;1-1-1,
tx_ttaddressextended_kurzwahl,
tx_ttaddressextended_by_tema,
tx_ttaddressextended_ausbildung;;;richtext[]:rte_transform[mode=ts],
tx_ttaddressextended_abschluss,
tx_ttaddressextended_sprachen,
tx_ttaddressextended_laufbahn;;;richtext[]:rte_transform[mode=ts],
tx_ttaddressextended_auszeichnungen;;;richtext[]:rte_transform[mode=ts],
tx_ttaddressextended_besondere_projekte;;;richtext[]:rte_transform[mode=ts],
tx_ttaddressextended_aktiv;;;richtext[]:rte_transform[mode=ts],
tx_ttaddressextended_interessen;;;richtext[]:rte_transform[mode=ts]'
);
Instead class t3lib_extMgm try use ExtensionManagementUtility:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_address', $tempColumns, 1);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_address', '...');
ExtensionManagementUtility Class Reference >>
I am using Prestashop HelperForm to generate a switch button. The status of the button depends on data generated from database. The problem is that the button is always set to false.
Here is the code :
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Champs pour feuille de soin'),
'icon' => 'icon-pencil'
),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_product',
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu1'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field1',
),
array(
'type' => 'radio',
'label' => $this->l('required'),
'name' => 'relab1',
'is_bool' => false,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'label1_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label1_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu2'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field2',
),
array(
'type' => 'radio',
'label' => $this->l('required'),
'name' => 'relab2',
'is_bool' => false,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'active_on',
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu3'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field3',
),
array(
'type' => 'switch',
'label' => $this->l('required'),
'name' => 'relab3',
'is_bool' => true,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'label3_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label3_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu4'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field4',
),
array(
'type' => 'checkbox',
'label' => $this->l('Required'),
'name' => 'label4',
'class' => 't',
'multiple' => true,
'values' => array(
'query' => array($label3),
'id' => 'label4',
'name' => 'label4',
'expand' => array(
'default' => 'show',
'show' => array('text' => $this->l('show'), 'icon' => 'plus-sign-alt'),
'hide' => array('text' => $this->l('hide'), 'icon' => 'minus-sign-alt')
),
)
),
),
'submit' => array(
'title' => $this->l('Save'),
'name' => $this->l('submitAddproduct'),
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$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 = 'submitUpdate';
$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(
$helper->fields_value['id_product'] = Tools::getValue('id_product'),
'relab4' => 1,
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
$helper->fields_value['contenu1'] = $contenu1;
$helper->fields_value['contenu2'] = $contenu2;
$helper->fields_value['contenu3'] = $contenu3;
$helper->fields_value['contenu4'] = $contenu4;
$helper->fields_value['relab1'] = (int)$relab1;
$helper->fields_value['relab2'] = (int)$relab2;
$helper->fields_value['relab3'] = (int)$relab3;
$helper->fields_value['relab4'] = (int)$relab4;
$helper->fields_value['id_customization_field1'] = $id_customization_field1;
$helper->fields_value['id_customization_field2'] = $id_customization_field2;
$helper->fields_value['id_customization_field3'] = $id_customization_field3;
$helper->fields_value['id_customization_field4'] = $id_customization_field4;
return $helper->generateForm(array($fields_form));
I guess you have this part of the code too ($helper is your HelperForm() object):
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
So with this function you need to return a relab2 value:
public function getConfigFieldsValues()
{
return array(
'relab2' => 1 // your value, 1 or 0
// other form values
);
}
You need to provide your form values to the HelperForm object.
Here is an example:
$fields_form = array(
'legend' => array(
'title' => $this->('My Form'),
),
'input' => array(
'type' => 'switch',
'label' => $this->l('required'),
'name' => 'relab2',
'is_bool' => true,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'label2_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label2_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
);
$val = getValFromDB(); //example
$helper = new HelperForm();
$helper->module = $this;
$helper->name_controller = 'example';
$helper->title = $this->displayName;
$helper->submit_action = 'example_action';
// [...]
// [...]
// Here you provide your values
$helper->fields_value = array('relab2' => $val);
return $helper->generateForm(array(array('form' => $fields_form)));
Hi I have had the same issue on prestashop 1.6 and 1.7 and I finally figured out the problem so I will share my findings with you guys.
So here is my switch :
array(
'type' => 'switch',
'label' => $this->trans('Captcha Test Mode', array(), 'Admin.Shipping.Feature'),
'name' => 'CORE_CAPTCHA_TEST_MODE',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->trans('Enabled', array(), 'Admin.Global'),
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->trans('Disabled', array(), 'Admin.Global'),
),
),
As you can see it has to have an explicit name CORE_CAPTCHA_TEST_MODE.
Where things become interesting is in the getConfigFormValues() method :
protected function getConfigFormValues()
{
return array(
'CORE_CAPTCHA_TEST_MODE' => Tools::getValue('CORE_CAPTCHA_TEST_MODE', Configuration::get('CORE_CAPTCHA_TEST_MODE', true)),
);
}
Unlike any other type of field where a simple Configuration::get would be enough to set the value in the field when the form is loaded for a switch we need to add Tools::getValue(...
Also got the same question, bot issue was elsewhere, just a switch button itself does nothing, you have to provide value data to it and then changes will be shown.
as other noted switch input itself:
array(
'type' => 'switch',
'label' => $this->l('Display map'),
'name' => 'my_data',
'is_bool' => true,
'values' => array(
array(
'id' => 'label2_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label2_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
and provide saved data to it right bellow
$helper->fields_value['my_data'] = Configuration::get('my_data');
I created new AdminReferenceController in prestashop back office with list and form for every item in list, and everything is working fine except one thing. When i try show image below upload button image is not displayed, (i check, image exist on server and url is valid). I use prestashop 1.5.6.0 Please check what i am doing wrong? Name and description values is properly displayed...
public function renderForm()
{
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Reference'),
'image' => '../modules/reference/logo.gif'
),
'input' => array(
array(
'type' => 'text',
'lang' => false,
'label' => $this->l('Reference name:'),
'name' => 'name',
'size' => 60,
'desc' => $this->l('Reference name')
),
array(
'type' => 'file',
'lang' => false,
'label' => $this->l('Reference image:'),
'name' => 'image',
'display_image' => true,
'desc' => $this->l('Upload Reference image from your computer')
),
array(
'type' => 'textarea',
'label' => $this->l('Reference description:'),
'name' => 'description',
'autoload_rte' => true,
'desc' => $this->l('Reference description')
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
if (!($obj = $this->loadObject(true)))
return;
$this->fields_value = array(
'image' => "<img src='/prestashop/img/reference/1.jpg'>",
'size' => '500',
'name' => 'test',
'description' => 'test'
);
return parent::renderForm();
}
Thanks
You can also use this code if it helps you
public function renderForm()
{
if (!($obj = $this->loadObject(true)))
return;
$image = _PS_MANU_IMG_DIR_.$obj->id.'.jpg';
$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350,
$this->imageType, true, true);
$image_size = file_exists($image) ? filesize($image) / 1000 : false;
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Add Maker'),
'icon' => 'icon-maker'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'required' => true
),
array(
'type' => 'file',
'label' => $this->l('Maker Image'),
'name' => 'image_url_maker',
'image' => $image_url ? $image_url : false,
'size' => $image_size,
'display_image' => true,
'col' => 6,
'hint' => $this->l('Upload a maker image from your computer.')
),
),
'submit' => array(
'title' => $this->l('Save'),
)
);
return parent::renderForm();
}
I have problem with Identical validator in ZF2. I have created following method:
public function getInputFilter()
{
if(!$this->inputFilter){
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'id',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
)));
$inputFilter->add($factory->createInput(array(
'name' => 'username',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 3,
'max' => 32
)
)
)
)));
$inputFilter->add($factory->createInput(array(
'name' => 'password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 3,
'max' => 32
)
)
)
)));
$inputFilter->add($factory->createInput(array(
'name' => 'retype-password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 3,
'max' => 32
),
array(
'name' => 'Identical',
'options' => array(
'token' => 'password' //I have tried $_POST['password'], but it doesnt work either
)
)
)
)
)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
Everything works fine except Identical validator which doesn't show anything(no msg, no error).
Tips are welcome, thanks in advance.
Actually it appears your array syntax is mis-placed is all. This should fix it for you:
public function getInputFilter()
{
if(!$this->inputFilter){
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'id',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
)));
$inputFilter->add($factory->createInput(array(
'name' => 'username',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 3,
'max' => 32
)
)
)
)));
$inputFilter->add($factory->createInput(array(
'name' => 'password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 3,
'max' => 32
)
)
)
)));
$inputFilter->add($factory->createInput(array(
'name' => 'retype-password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 3,
'max' => 32
),
),
array(
'name' => 'Identical',
'options' => array(
'token' => 'password' //I have tried $_POST['password'], but it doesnt work either
)
)
)
)));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}