Jump to content

how to create a form using helper class


NaveenYadav

Recommended Posts

Hello, I want to create form using helper class.

 

I am creating a module which is making a Admin tab when I am click on this tab it will redirect to the corresponding controller,on this controller I extends AdminTab class .

 

Admin class have a function display in which our content show but my question is if we create form manually then it will created but I want to create form in this using helper class.

 

So please help me

 

Note : I have been created form using helper class but by extending Module class .

 

Thanks

Link to comment
Share on other sites

Hello, I want to create form using helper class.

 

I am creating a module which is making a Admin tab when I am click on this tab it will redirect to the corresponding controller,on this controller I extends AdminTab class .

 

Admin class have a function display in which our content show but my question is if we create form manually then it will created but I want to create form in this using helper class.

 

So please help me

 

Note : I have been created form using helper class but by extending Module class .

 

Thanks

i suggest you to view editorial module which is prestashop code module. here is the code from there and it will help you to build form using form class.

private function initForm()
{
 $languages = Language::getLanguages(false);
 foreach ($languages as $k => $language)
  $languages[$k]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT'));
 $helper = new HelperForm();
 $helper->module = $this;
 $helper->name_controller = 'editorial';
 $helper->identifier = $this->identifier;
 $helper->token = Tools::getAdminTokenLite('AdminModules');
 $helper->languages = $languages;
 $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
 $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');
 $helper->allow_employee_form_lang = true;
 $helper->toolbar_scroll = true;
 $helper->toolbar_btn = $this->initToolbar();
 $helper->title = $this->displayName;
 $helper->submit_action = 'submitUpdateEditorial';

 $this->fields_form[0]['form'] = array(
  'tinymce' => true,
  'legend' => array(
   'title' => $this->displayName,
   'image' => $this->_path.'logo.gif'
  ),
  'submit' => array(
   'name' => 'submitUpdateEditorial',
   'title' => $this->l('Save '),
   'class' => 'button'
  ),
  'input' => array(
   array(
 'type' => 'text',
 'label' => $this->l('Main title'),
 'name' => 'body_title',
 'lang' => true,
 'size' => 64,
 'hint' => $this->l('Appears along top of your homepage'),
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Subheading'),
 'name' => 'body_subheading',
 'lang' => true,
 'size' => 64,
   ),
   array(
 'type' => 'textarea',
 'label' => $this->l('Introductory text'),
 'name' => 'body_paragraph',
 'lang' => true,
 'autoload_rte' => true,
 'hint' => $this->l('For example... explain your mission, highlight a new product, or describe a recent event.'),
 'cols' => 60,
 'rows' => 30
   ),
   array(
 'type' => 'file',
 'label' => $this->l('Homepage logo'),
 'name' => 'body_homepage_logo',
 'display_image' => true
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Homepage logo link'),
 'name' => 'body_home_logo_link',
 'size' => 33,
   ),
   array(
 'type' => 'text',
 'label' => $this->l('Homepage logo subheading'),
 'name' => 'body_logo_subheading',
 'lang' => true,
 'size' => 33,
   ),
  )
 ); 
 return $helper;
}

Link to comment
Share on other sites

I try this but it give this errror.

 

Fatal error: Call to undefined method category::addJS() in /home/sparxmgnt/public-html/Presta_Google/classes/helper/HelperForm.php on line 74

see the error happen to addJs call you try to add a non declare class did you initialize the object like category = new Category(); or Category::.. as the class name is Category not small later category. Please check again.

Link to comment
Share on other sites

Here is my code ,please check

 

<?php

class category extends AdminTab

{

public function __construct(){

global $cookie;

$cont = 'category';

$tkn = Tools::getValue('token');

$this->url ='index.php?controller='.$cont.'&token='.$tkn;

parent::__construct();

}

 

private function initForm()

{

$languages = Language::getLanguages(false);

foreach ($languages as $k => $language)

$languages[$k]['is_default'] = (int)($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT'));

 

$helper = new HelperForm();

$helper->module = $this;

$helper->name_controller = 'category';

$helper->identifier = $this->identifier;

$helper->token = Tools::getAdminTokenLite('AdminModules');

$helper->languages = $languages;

$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

$helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT');

$helper->allow_employee_form_lang = true;

$helper->toolbar_scroll = true;

$helper->toolbar_btn = $this->initToolbar();

$helper->title = $this->displayName;

$helper->submit_action = 'submitUpdateEditorial';

 

$this->fields_form[0]['form'] = array(

'tinymce' => true,

'legend' => array(

'title' => $this->displayName,

'image' => $this->_path.'logo.gif'

),

'submit' => array(

Here is my code ,please check

category is

'name' => 'submitUpdateEditorial',

'title' => $this->l(' Save '),

'class' => 'button'

),

 

'input' => array(

array(

'type' => 'text',

'label' => $this->l('Main title'),

'name' => 'body_title',

'lang' => true,

'size' => 64,

'hint' => $this->l('Appears along top of homepage'),

),

 

array(

'type' => 'text',

'label' => $this->l('Subheading'),

'name' => 'body_subheading',

'lang' => true,

'size' => 64,

),

 

array(

'type' => 'textarea',

'label' => $this->l('Introductory text'),

'name' => 'body_paragraph',

'lang' => true,

'autoload_rte' => true,

'hint' => $this->l('Text of your choice; for example, explain your mission, highlight a new product, or describe a recent event.'),

'cols' => 60,

'rows' => 30

),

array(

'type' => 'file',

'label' => $this->l('Homepage logo'),

'name' => 'body_homepage_logo',

'display_image' => true

),

array(

'type' => 'text',

'label' => $this->l('Homepage logo link'),

'name' => 'body_home_logo_link',

'size' => 33,

),

array(

'type' => 'text',

'label' => $this->l('Homepage logo subheading'),

'name' => 'body_logo_subheading',

'lang' => true,

'size' => 33,

),

)

);

 

return $helper;

}

 

private function initToolbar()

{

$this->toolbar_btn['save'] = array(

'href' => '#',

'desc' => $this->l('Save')

);

 

return $this->toolbar_btn;

}

 

public function display()

{

$helper = $this->initForm();

$a = $helper->generateForm($this->fields_form);

echo $a;

}

}

?>

Link to comment
Share on other sites

  • 1 year later...
  • 10 months later...
  • 5 years later...

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