Jump to content

Display radio button in BO configuration module


tarek.fellah

Recommended Posts

Hi guys,

 

I tried to display a radio button in BO with cms pages id as values,

 

I tried this code but only the radio  label  is displayed.

 $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
     $id_lang = (int)Context::getContext()->language->id;
    
    $categories = $this->getCMSCategories(false, 1, (int)$id_lang);
    $options = array();
    foreach ($categories as $category)
    {
    	
    	$pages = $this->getCMSPages((int)$category['id_cms_category'], false, (int)$id_lang);
    	foreach ($pages as $page){
    		$radioelement =array(
    				'id' => 'id_cms'.(int)$page['id_cms'],
    				'value' => (int)$page['id_cms'],
    				'label' => $page['meta_title']
    		);
    	$options[]	= $radioelement;
    	}	
    }
    //$spacer = str_repeat(' ', $this->spacer_size * (int)$depth);
    
    $fields_form[0]['form'] = array(
    		'legend' => array(
    				'title' => $this->l('Settings'),
    		),
    
    		'input' => array(
    				array(
    						'type' => 'text',
    						'label' => $this->l('Nombre de caractères'),
    						'name' => 'nb_chars',
    						'size' => 20,
    						'required' => true
    				),
    				 array(
    				'type' => 'radio',
    				'label' => $this->l('choose a cms page'),
    				'name' => 'id_cms',
    				'class' => 't',
    				 'values' => $options,
    				'is_bool' => true,
    				'required' => true
    		)
    		),
    		
    		'submit' => array(
    				'title' => $this->l('Save'),
    				'class' => 'button',
    				'name'=>'submitCmsReadMore'
    		)
    );

Thanks in advance.

Link to comment
Share on other sites

I solved a part of the problem, the radio button is displayed

i changed
$categories = $this->getCMSCategories(false, 1, (int)$id_lang); to
$categories = $this->getCMSCategories(false, 0, (int)$id_lang);

 

but i get a smarty  error

Notice: Undefined index: nb_chars in /var/www/presta/cache/smarty/compile/7d2a4e588611a8a1dd049f82d14a4ae0b20fe990.file.form.tpl.php on line 228

nb_chars is the name of the input text, what should i modify?

Thanks.

Link to comment
Share on other sites

  • 7 years later...

7 years later but, do you put your nb_cars into your getConfigFormValues()? It return an array to load saved config, and for load your tpl, you should configure all your input value (even it's the first time, it will be null or whatever). If you don't, smarty will not reconized this variable because you don't send it from getContent().

If you have any question, you can ask or check here: http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class

Gd! 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...