WeeklyJr Posted July 21, 2019 Share Posted July 21, 2019 Hi, I'm writing a custom module in Prestashop 1.7.5.2 and need to have a form. I've created a separate tab for my module and on the new page I have a table. When I want to add a new record I have a form and it shows correctly. Unfortunately, when I submit filled/blank form I get an error: access to undeclared static property $definition. I have a $definiton variable in my model, but somehow it still doesn't work. Here it is: /** * @see ObjectModel::$definition */ public static $definition = array ( 'table' => 'p_c', 'primary' => 'id_p_c', 'fields' => array( 'id_p_c' => array('type' => self::TYPE_INT), 'name' => array('type' => self::TYPE_STRING), 'start' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'end' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); And here is how I create the form in a controller: public function renderForm() { $this->fields_form = array( 'legend' => array( 'title' => Context::getContext()->getTranslator()->trans('My module'), 'icon' => 'icon-ticket' ), 'input' => array( array( 'type' => 'text', 'label' => Context::getContext()->getTranslator()->trans('Name'), 'name' => 'name', 'required' => true, 'col' => 4, ), array( 'type' => 'date', 'label' => Context::getContext()->getTranslator()->trans('Start'), 'name' => 'start', 'required' => true, 'col' => 4, ), array( 'type' => 'date', 'label' => Context::getContext()->getTranslator()->trans('End'), 'name' => 'end', 'required' => true, 'col' => 4, ), array( 'type' => 'text', 'label' => Context::getContext()->getTranslator()->trans('Percentage'), 'name' => 'percentage', 'required' => true, 'col' => 4, ), array( 'type' => 'checkbox', 'name' => 'all_users', 'col' => 4, 'values' => array( 'query' => array( array( 'id' => 'on', 'name' => Context::getContext()->getTranslator()->trans('All users'), 'val' => 1 ) ), 'id' => 'id', 'name' => 'name', ), ), ), 'submit' => array( 'title' => Context::getContext()->getTranslator()->trans('Save'), ), ); return parent::renderForm(); } I've been looking for any solution, but nothing fits to this problem. I also can't find any tutorial how to create a form in a custom module - official docs doesn't help and I'm out of sources after hours spent on crawling the Net. Any help is highly appreciated! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now