Jump to content

Form creation in Back office


Venky967

Recommended Posts

Hello everyone, I'm very much new to prestashop but still managed to add a tab in the menu items by creating a new module. Now i need to create a form that contains some input fields and button just like a sign up page after clicking on the tab(CRUD Model) that i created.

 

please have a look at the upload image.

 

Thank you in advance.

post-1368481-0-79065600-1486635004_thumb.png

Link to comment
Share on other sites

This page, in addition to providing useful validator for checking your module:

 

https://validator.prestashop.com/auth/login

 

also contains a link at the top of the page to a module generator, which provides a structure for what files (e.g. template and controller) you'll need for your module.

 

If you generate a module, you can examine its structure and see what you need for your module.

Link to comment
Share on other sites

 

<?php

 

 

class YourModule extends Module

{

 

//tabs to be created in the backoffice menu

protected $tabs = [

[

'name' => 'Tab Creation',

'className' => 'tabcreation',

'active' => 1,

//submenus

'childs' => [

[

'active' => 1,

'name' => 'Tab1',

'className' => 'tab1',

],

 

],

],

];

 

 

 

//add a tab in the backoffice menu

public function addTab(

$tabs,

$id_parent = 0

)

{

foreach ($tabs as $tab)

{

$tabModel = new Tab();

$tabModel->module = $this->name;

$tabModel->active = $tab['active'];

$tabModel->class_name = $tab['className'];

$tabModel->id_parent = $id_parent;

 

//tab text in each language

foreach (Language::getLanguages(true) as $lang)

{

$tabModel->name[$lang['id_lang']] = $tab['name'];

}

 

$tabModel->add();

 

//submenus of the tab

if (isset($tab['childs']) && is_array($tab['childs']))

{

$this->addTab($tab['childs'], Tab::getIdFromClassName($tab['className']));

}

}

return true;

}

 

//remove a tab and its childrens from the backoffice menu

public function removeTab($tabs)

{

foreach ($tabs as $tab)

{

$id_tab = (int) Tab::getIdFromClassName($tab["className"]);

if ($id_tab)

{

$tabModel = new Tab($id_tab);

$tabModel->delete();

}

 

if (isset($tab["childs"]) && is_array($tab["childs"]))

{

$this->removeTab($tab["childs"]);

}

}

 

return true;

}

 

public function install()

{

//module installation

$success = parent::install();

 

//if the installation fails, return error

if (!$success)

{

return false;

}

 

//create the tabs in the backoffice menu

$this->addTab($this->tabs);

 

return true;

}

 

public function uninstall(){

$this->removeTab($this->tabs);

return parent::uninstall();

}

}

 

It will be solved.

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