Jump to content

Help with helper class (PS 1.6.1.4)


Recommended Posts

So i need to make a configuration page for my own module, and i've some trouble using the helper class. So the default behaviour is 


'input' => array(
    array(
        'type' => 'text',
        'label' => $this->l('Configuration value'),
        'name' => 'MYMODULE_NAME',
        'size' => 20,
        'required' => true
    ))


...generates the following HTML tags:


<label>Configuration value </label>
<div class="margin-form">
  <input id="MYMODULE_NAME" class="" type="text" size="20" value="my friend" name="MYMODULE_NAME">
  <sup>*</sup>
<div class="clear"></div>

it set id and name as the string in 'name' => 'MYMODULE_NAME' and sets the value with the value of MYMODULE_NAME saved in the ps_configuration table... Is this behaviour overridable?
The thing i need is something like
 

$value = 'someString';

'input' => array(
    array(
        'type' => 'text',
        'label' => $this->l('Configuration value'),
        'name' => 'myCustomName',
        'id' => 'myCustomID'
        'value' => $myValue
        'size' => 20,
        'required' => true
    ))
...generates the following HTML tags:
<label>Configuration value </label>
<div class="margin-form">
  <input type="text" id="myCustomID" name="myCustomName" size="20" value='someString'>
  <sup>*</sup>
<div class="clear"></div>

PS: $value is stored in a different table from ps_configuration.
Thanks!

Edited by TheGGTheory (see edit history)
Link to comment
Share on other sites

Second example input would work except for setting the value, you can pass different values for ID and NAME, the 'value' is taken from the fields_value array you need to pass, and will use the value for 'name' to find it in the array, there is nothing to stop you assigning your $value to a field called 'myCustomName' inside that array though so the helper can find it though.

 

Or, yes, it is possible to override the templates, not documented very well, but there are examples in this forum, I would say it's overkill for this task.

 

Or, you can create your own configuration template, and display that:

$tpl = $this->context->smarty->createTemplate($this->getTemplatePath('YOUR_TEMPLATE.tpl'));
$tpl->assign(
    array(
        'languages' => $this->context->controller->getLanguages(),
        'link' => $this->context->link,
        'defaultFormLanguage' => (int)Configuration::get('PS_LANG_DEFAULT'),
        'admin_link' => $this->context->link->getAdminLink('YOUR_CONTROLLER'),
        'fields_value' => $this->getModuleConfigFieldsValues(),
    )
);
$html = $tpl->fetch();
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...