compsoul.dev Posted June 30, 2023 Share Posted June 30, 2023 Using FormBuilderModifier, I created a form for myself. Everything works, it saves itself in the database the content from the form when saving. But how do I get the data from the database and save it in the form fields so that the user knows what he is editing? The function that creates the form: One of the fields on the form: I would like to change the date option to the one I retrieve from the database depending on the language, I have looked everywhere but it is nowhere to be found. Link to comment Share on other sites More sharing options...
compsoul.dev Posted June 30, 2023 Author Share Posted June 30, 2023 public function hookActionCMSPageFormBuilderModifier($params) { $formBuilder = $params['form_builder']; $fields = $this->field_definitions; foreach ($fields as $key => $value) { if (isset($fields[$key]['type'])) { $formBuilder->add($key, $fields[$key]['type'], $fields[$key]['options']); } } } Link to comment Share on other sites More sharing options...
compsoul.dev Posted June 30, 2023 Author Share Posted June 30, 2023 (edited) Edited June 30, 2023 by compsoul.dev 500 (see edit history) Link to comment Share on other sites More sharing options...
compsoul.dev Posted June 30, 2023 Author Share Posted June 30, 2023 Sorry for so many posts, but when I added the code in one it blocked me Link to comment Share on other sites More sharing options...
ps8modules Posted June 30, 2023 Share Posted June 30, 2023 Hi, https://devdocs.prestashop-project.org/8/development/components/form/types-reference/translatable/ Link to comment Share on other sites More sharing options...
compsoul.dev Posted June 30, 2023 Author Share Posted June 30, 2023 Hey, thanks for the reply. I've seen the documentation, but nowhere is there an answer on how to put language dependent data in the form. Link to comment Share on other sites More sharing options...
ps8modules Posted July 1, 2023 Share Posted July 1, 2023 (edited) Hi. Please specify: Do you need a sample of how to load data from the database? Is your new field added to the cms_lang table? Edited July 1, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted July 1, 2023 Share Posted July 1, 2023 I have created a sample (not fully formated) module. The module add a text and textarea field. When installed, it adds two fields to the cms_lang table. ps8mod_cmsfield.zip 1 Link to comment Share on other sites More sharing options...
compsoul.dev Posted July 1, 2023 Author Share Posted July 1, 2023 Thanks for your help but I have already found a solution. I was referring to the line: $formBuilder->setData($params['data']); I didn't know how I should replace the form fields, with the completed data from the database. 1 Link to comment Share on other sites More sharing options...
ps8modules Posted July 1, 2023 Share Posted July 1, 2023 (edited) This is a complete example for others who will be looking for a solution. You can also mark the topic as resolved 😉 Edited July 1, 2023 by ps8moduly.cz (see edit history) 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