Jump to content

[RESOLU] HelpForm Extension de fichier


Recommended Posts

Bonjour,

 

Je développe un module et j'aimerais savoir comme ajouter un filtre dans le HelpForm pour forcer un format de fichier 

array(
                        'type' => 'file',
                        'label' => $this->l('Image 1'),
                        'name' => 'uploadedfile1',
                        'id' => 'uploadedfile1',
                        'required' => true,
                        'desc' => $this->l('Set the image (GIF)'),
                        'accept' => 'image/gif'
                    ),

Mais le accept ne semble pas fonctionner.

Avez-vous une idée?

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

Salut,

 

Tu peux utiliser l'override du tpl du helper form dans ton module pour ajouter la fonctionnalité ;)

 

Si tu affiches ton helper form dans la méthode getContent() de ton module, tu dois placer ton fichier là :

modules/MODULE_NAME/views/templates/admin/_configure/helpers/form/form.tpl

Si tu utilises un controller dans ton module :

modules/MODULE_NAME/views/templates/admin/CONTROLLER_NAME/helpers/form/form.tpl

Pour CONTROLLER_NAME, Prestashop utilise Tools::toUnderscoreCase(substr($this->controller_name, 5)) pour déterminer sa valeur. 

 

Exemple de fichier tpl pour l'override :

{extends file="helpers/form/form.tpl"}
{block name="input"}
{if $input.type == 'file'}
// Ton code perso
{else}
     {$smarty.block.parent}
{/if}
{/block}

A+

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

  • 2 weeks later...

Bonjour,

 

j'ai tenté de placé mon fichier form.tpl dans

 

modules/MODULE_NAME/views/templates/admin/_configure/helpers/form/form.tpl

 

Mais il ne semble pas le prendre en compte

 

Pourtant mon fichier est bien dans le getContent

 

Dans mon getContent j'ai ceci 

$this->_html .= $this->renderForm(); 

Et dans mon renderForm j'ai bien 

array(
                        'type' => 'number',
                        'label' => $this->l('Maximum size'),
                        'desc' => $this->l('Test'),
                        'name' => 'SIZE',
                        'required' => true,
                        'min' => 10,
                        'max' => 90
                    ),

Mon module n'a pas de controller...

 

As-tu une idée?

Link to comment
Share on other sites

  • 5 months later...

Bonjour j'ai le même problème.  Je n'utilise pas de controller et j'ai bien mis  

$helper->module = $this;

Avez vous une idée de ce qui peut manquer?

On 11/08/2017 at 10:29 AM, Matt75 said:

Salut,

 

Lorsque tu créé ton helper form, n'aurais-tu pas oublié de passer ton module au helper ?


$helper->module = $this;

A+

 

Link to comment
Share on other sites

Bonjour

Oui c'est sûr que ça sera plus facile :D

Voila mon code

getContent

public function getContent()
   {
   	$this->processConfiguration();
   	$html_confirmation_message=$this->display(__FILE__,'confirmationMessage.tpl');
	$html_form=$this->renderForm();
	return $html_confirmation_message.$html_form;
   }

renderForm

 public function renderForm()
   {
	   $this->context->controller->addCSS($this->_path.'views/css/font/flaticon.css',all);

   	$fields_form= array(
   		'form'=> array(
   			'legend'=> array(
   				'title'=> $this->l('Buton top Module configuration'),
   				'icon'=>'icon-enveloppe'
   			),
   			'input'=> array(
   				array(
   				'type' => 'color',
   				'label' => $this->l('Background color of the button'),
   				'name' => 'color',
   				'hint' => $this->l('Status will be highlighted in this color. HTML colors only.').' "lightblue", "#CC6600")'
   			),
   			array(
   				'type' => 'color',
   				'label' => $this->l('Police color of the button'),
   				'name' => 'policeColor',
   				'hint' => $this->l('Status will be highlighted in this color. HTML colors only.').' "lightblue", "#CC6600")'
   			),
   			array(
   				'type'=>'radio',
   				'label'=>$this->l('Button shape'),
   				'name'=>'shape',
   				'required'=> true,

   				'values' => array(
   					array(
   						'id'=>'carre',
   						'value'=>'carre',
   						'label'=> $this->l('Square')

   					), array(
   						'id'=>'round',
   						'value'=>'rond',
   						'label'=> $this->l('Round')

   					)
   				),
   				),

				array(
	   				'type'=>'radio',
	   				'label'=>$this->l('Icon'),
	   				'name'=>'icon',
	   				'required'=> true,

	   				'values' => array(
	   					array(
	   						'id'=>'flaticon-arrows-8',
	   						'value'=>'flaticon-arrows-8',
							'label' => $this->l('flaticon-arrows-8'),
							'icon' => 'flaticon-arrows-8'


	   					), array(
	   						'id'=>'flaticon-arrows-9',
	   						'value'=>'flaticon-arrows-9',
	   						'label'=> $this->l('flaticon-arrows-9'),
							'icon' => 'flaticon-arrows-9'

	   					)
	   				),
	   				),


   			array(
   				'type'=>'text',
   				'label'=>$this->l('Text'),
   				'name'=>'message'
   			),

   		),
   		'submit' => array(
   			'title' => $this->l('Save'),
   			'class' => 'btn btn-default pull-right'
   		)
   	),
   );
   $helper= new HelperForm();
   $helper->table=$this->table;
   $helper->module = $this;
   $helper->default_form_language = $this->context->language->id;
   $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
   $helper->identifier = $this->identifier;
   $helper->submit_action='submit_buttontop_form';
   $helper->currentIndex=AdminController::$currentIndex.'&configure='.$this->name;
   $helper->token=Tools::getAdminTokenLite('AdminModules');
   $helper->tpl_vars= array(
   	'fields_value'=>array(
   		'message'=>Tools::getValue('message',Configuration::get('BUTTONTOP_MESSAGE')),
   		'shape'=>Tools::getValue('shape',Configuration::get('BUTTONTOP_SHAPE')),
   		'color'=>Tools::getValue('color',Configuration::get('BUTTONTOP_COLOR')),
   		'policeColor'=>Tools::getValue('policeColor',Configuration::get('BUTTONTOP_POLICECOLOR')),
		'icon'=>Tools::getValue('icon',Configuration::get('BUTTONTOP_ICON')),
   	),
   	'languages'=>$this->context->controller->getLanguages()
   );
   return $helper->generateForm(array($fields_form));
   }

et form.tpl

{extends file="helpers/form/form.tpl"}

{block name="input"}
    {if $input.name == 'icon'}
        <div class="col-lg-9">
            {foreach $input.values as $value}
                <div class="radio {if isset($input.class)}{$input.class|escape:'htmlall':'UTF-8'}{/if}">
                    {strip}
                        <label>
                            <input type="radio"	name="{$input.name|escape:'htmlall':'UTF-8'}" id="{$value.id|escape:'htmlall':'UTF-8'}" value="{$value.value|escape:'html':'UTF-8'}"{if $fields_value[$input.name] == $value.value} checked="checked"{/if}{if isset($input.disabled) && $input.disabled} disabled="disabled"{/if}/>
                            <i width="50px" height="50px" class="{$value.icon|escape:'htmlall':'UTF-8'}" alt=""></i>
                            {$value.label|escape:'htmlall':'UTF-8'}
                        </label>
                    {/strip}
                </div>
                {if isset($value.p) && $value.p}<p class="help-block">{$value.p|escape:'htmlall':'UTF-8'}</p>{/if}
            {/foreach}
        </div>
        {else}
            {$smarty.block.parent}
        {/if}
        {/block}

 

Merci d'avance

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...