Php 帮助在Prestashop中执行和复选框
我尝试将复选框添加到PrestaShop 1.5的模块配置中。我像在手册中一样使用HelperForm,但是有空的$helper->fields\u值Php 帮助在Prestashop中执行和复选框,php,prestashop,prestashop-1.5,Php,Prestashop,Prestashop 1.5,我尝试将复选框添加到PrestaShop 1.5的模块配置中。我像在手册中一样使用HelperForm,但是有空的$helper->fields\u值 public function getContent() { $output = null; if (Tools::isSubmit('submit'.$this->name)) { $fast_email = strval(Tools::getValue('fast_email'));
public function getContent()
{
$output = null;
if (Tools::isSubmit('submit'.$this->name))
{
$fast_email = strval(Tools::getValue('fast_email'));
if (!$fast_email || empty($fast_email) || !Validate::isGenericName($fast_email))
$output .= $this->displayError( $this->l('Invalid Configuration value') );
else
{
Configuration::updateValue('fast_email', $fast_email);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
$fast_email_sender = strval(Tools::getValue('fast_email_sender'));
if ( !Validate::isGenericName($fast_email_sender))
$output .= $this->displayError( $this->l('Invalid Configuration value') );
else
{
Configuration::updateValue('fast_email_sender', $fast_email_sender);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
$fast_phone = strval(Tools::getValue('fast_phone'));
Configuration::updateValue('fast_phone', $fast_phone);
var_dump(Tools::getValue('fast_phone'));
$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');
$options = array(
array(
'id_option' => 1, // The value of the 'value' attribute of the <option> tag.
'name' => 'email' // The value of the text content of the <option> tag.
),
array(
'id_option' => 2,
'name' => 'phone'
),
);
// var_dump($options);
// Init Fields form array
$fields_form[0]['form'] = array(
'legend' => array(
'title' => $this->l('Settings'),
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('admin email'),
'name' => 'fast_email',
'size' => 20,
'required' => true
)
,
array(
'type' => 'checkbox', // This is an <input type="checkbox"> tag.
'label' => $this->l('Options'), // The <label> for this <input> tag.
'desc' => $this->l('Choose options.'), // A help text, displayed right next to the <input> tag.
'name' => 'fast_phone', // The content of the 'id' attribute of the <input> tag.
'values' => array(
'query' => $options, // $options contains the data itself.
'id' => 'id_option', // The value of the 'id' key must be the same as the key for 'value' attribute of the <option> tag in each $options sub-array.
'name' => 'name' // The value of the 'name' key must be the same as the key for the text content of the <option> tag in each $options sub-array.
),
),
array(
'type' => 'radio',
'label' => $this->l('email'),
'name' => 'fast_email_sender', // The content of the 'id' attribute of the <input> tag.
'required' => true,
'class' => 't',
'values' => array( // $values contains the data itself.
array(
'id' => 'active_on', // The content of the 'id' attribute of the <input> tag, and of the 'for' attribute for the <label> tag.
'value' => 1, // The content of the 'value' attribute of the <input> tag.
'label' => $this->l('Enabled') // The <label> for this radio button.
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
$helper = new HelperForm();
// Module, t oken 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['fast_email'] = Configuration::get('fast_email');
$helper->fields_value['fast_email_sender'] = Configuration::get('fast_email_sender');
$helper->fields_value['fast_phone'] = Configuration::get('fast_phone');
return $helper->generateForm($fields_form);
}
公共函数getContent()
{
$output=null;
if(工具::isSubmit('submit'.$this->name))
{
$fast_email=strval(工具::getValue('fast_email');
如果(!$fast_email | |空($fast_email)| |!验证::isGenericName($fast_email))
$output.=$this->displayError($this->l('Invalid Configuration value');
其他的
{
配置::updateValue('fast\u email',$fast\u email);
$output.=$this->displayConfirmation($this->l('Settings updated'));
}
$fast\u email\u sender=strval(工具::getValue('fast\u email\u sender');
如果(!Validate::isGenericName($fast\u email\u sender))
$output.=$this->displayError($this->l('Invalid Configuration value');
其他的
{
配置::updateValue('fast\u email\u sender',$fast\u email\u sender);
$output.=$this->displayConfirmation($this->l('Settings updated'));
}
$fast\u phone=strval(工具::getValue('fast\u phone');
配置::updateValue('fast\u phone',$fast\u phone);
var_dump(Tools::getValue('fast_phone');
$output.=$this->displayConfirmation($this->l('Settings updated'));
}
返回$output.$this->displayForm();
}
公共函数displayForm()
{
//获取默认语言
$default_lang=(int)配置::get('PS_lang_default');
$options=array(
排列(
'id_option'=>1,//标记的'value'属性的值。
'name'=>'email'//标记的文本内容的值。
),
排列(
“id_选项”=>2,
“名称”=>“电话”
),
);
//var_dump(期权);
//初始化字段形成数组
$fields_form[0]['form']=数组(
“图例”=>数组(
'title'=>$this->l('Settings'),
),
'输入'=>数组(
排列(
'类型'=>'文本',
'label'=>$this->l('admin email'),
'name'=>'fast_email',
“大小”=>20,
“必需”=>true
)
,
排列(
'键入'=>'复选框',//这是一个标记。
'label'=>$this->l('Options'),//此标记的名称。
'desc'=>$this->l('Choose options'),//一个帮助文本,显示在标记旁边。
'name'=>'fast_phone',//标记的'id'属性的内容。
'值'=>数组(
“query”=>$options,//$options包含数据本身。
'id'=>'id_option',//id'键的值必须与每个$options子数组中标记的'value'属性的键相同。
'name'=>'name'//name'键的值必须与每个$options子数组中标记文本内容的键相同。
),
),
排列(
'类型'=>'无线电',
'label'=>$this->l('email'),
'name'=>'fast\u email\u sender',//标记的'id'属性的内容。
“必需”=>true,
'class'=>'t',
“values”=>数组(//$values包含数据本身。
排列(
'id'=>'active_on',//标记的'id'属性和标记的'for'属性的内容。
'value'=>1,//标记的'value'属性的内容。
'label'=>$this->l('Enabled')//此单选按钮的名称。
),
排列(
'id'=>'active\u off',
“值”=>0,
'label'=>$this->l('Disabled')
)
),
)
),
“提交”=>数组(
'title'=>$this->l('Save'),
“类”=>“按钮”
)
);
$helper=新的HelperForm();
//模块、OK和currentIndex
$helper->module=$this;
$helper->name\u controller=$this->name;
$helper->token=Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex=AdminController::$currentIndex.&configure=。$this->name;
//语言
$helper->default\u form\u language=$default\u lang;
$helper->allow\u employee\u form\u lang=$default\u lang;
//标题和工具栏
$helper->title=$this->displayName;
$helper->show_toolbar=true;//false->remove toolbar
$helper->toolbar\u scroll=true;//是->工具栏始终显示在屏幕顶部。
$helper->submit\u action='submit'。$this->name;
$helper->toolbar\u btn=数组(
“保存”=>
排列(
'desc'=>this->l('Save'),
'href'=>AdminController::$currentIndex.&configure='.$this->name.&save'.$this->name。
“&token=”。工具::getAdminTokenLite('AdminModules'),
),
“后退”=>数组(
'href'=>AdminController::$currentIndex.&token='。工具::getAdminTokenLite('AdminModules'),
'desc'=>$this->l('返回列表')
)
);
//负载电流值
$helper->fields_value['fast_email']=Configuration::get('fast_email');
$helper->fields_value['fast_email_sender']=Configuration::get('fast_email_sender');
$helper->fields_value['fast_phone']=Configuration::get('fast_phone');
返回$helper->generateForm($f)
public function getContent()
{
$output = null;
// Save settings values
if (Tools::isSubmit('submit'.$this->name)) // Check if form is submitted
{
Configuration::updateValue('MODULE_OPTION1', Tools::getValue('MODULE_OPTION1'));
Configuration::updateValue('MODULE_OPTION2', Tools::getValue('MODULE_OPTION2'));
Configuration::updateValue('MODULE_OPTION3', Tools::getValue('MODULE_OPTION3'));
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
return $output.$this->displayForm();
}