简体   繁体   中英

How to use HelperForm from the FrontController in PrestaShop 1.6

I was trying to do a form with the helperForm, but it was imposible. I was following the official documentation, but was imposible for me from the FrontControler.

http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class

Can i do that??

The error that show to me is:

Uncaught --> Smarty: Unable to load template file 'helpers/form/form.tpl'

And my class is:

public function renderForm()
  { 
    $fields_form = array( 'form' => array(
      'legend' => array(       
        'title' => $this->module->l('Edit carrier'),       
        'image' => '../img/admin/icon_to_display.gif'   
      ),   
      'input' => array(       
        array(           
          'type' => 'text',
          'name' => 'shipping_method',
         ),
      ),
      'submit' => array(
        'title' => $this->module->l('Save'),       
        'class' => 'btn btn-default pull-right'   
      )
    ));

    $helper = new HelperForm();
    $helper->show_toolbar = false;
    $helper->table = $this->table;
    $this->fields_form = array();

    $helper->identifier = $this->identifier;
    $helper->submit_action = 'submitBlockCart';

    return $helper->generateForm(array($fields_form));
}

I'm going crazy....

The answer is simple: You CAN NOT use HelperForm from the FrontEnd.

As far as I know you can use the helperForm only in the BackOffice, so I don't think you can in the front.

I've already seen this kind of error on many thread. Is your admin/themes/your_theme/template/helpers/form/form.tpl present on your server and with the right access permissions?

Sometimes the whole helpers directory is missing for strange reasons.


EDIT Helper Form is only available for Back Office. You can't use it from a FrontController context.

Actually, I don't know if you should , but you certainly can use the HelperForm in a custom module.

Have a look at the function createTemplate from the Helper class (which HelperForm extends) in /classes/helper/Helper.php and in particular at this piece of code:

elseif ($this->module) {
    $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name;
}

You can see that if you define the property module , the helper will use the template form.tpl inside your module's folder, under /views/templates/admin/_configure/helpers/form/ .

So what you need to do is:

  1. Copy form.tpl from admin/themes/default/template/helpers/form/form.tpl to the above-mentioned path in your module
  2. Place $helper->module = $this; before calling generateForm()

Note: In addition, you might also want to define $helper->tpl_vars to be able to use the property name of your inputs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM