pl.sabotinov Posted February 22, 2023 Share Posted February 22, 2023 (edited) Hello everybody, Presta 1.7.7.5 i am newbie in creating modules, but still have decided to solve one small problem by creating a very simple module, which adds 2 fields in the carrrier / checkout step. These fields are saved in the ps_orders table and will be used and displayed on the new order mail template. But the problem is that i can not display the two input text fields in the carrier step of FO. So i can not fill the fields with information. Here the code of my main class: Full text is attached below as text file as cloudflare blocks the post with code even in code tags I am using the hookdisplayAfterCarrier - to display the text fields there. But in the FrontOffice at the position where these text fields should be displayed i receive only: Array And in console the html generated is: in text file also below So the example where i have taken the code this definition is put in constructor in the override of class. But i do not want to make this override. Should i put this definition in constructor of my main class also? Would you help me please to display these fields in FO. I hope the other part of the code is correct. What concerns the database - the fields are added there. They are in orders table, when i install module. new_topic_module.docx Edited February 24, 2023 by pl.sabotinov doc file first list empty (see edit history) Link to comment Share on other sites More sharing options...
pl.sabotinov Posted February 24, 2023 Author Share Posted February 24, 2023 Hello again, i think i've found the problematic part of my code. So in my function: public function hookDisplayAfterCarrier($params) { return [ (new FormField) ->setName('my_extrafield_1') ->setType('text') //->setRequired(true) ->setLabel($this->l('My extrafield carrier branch 1')), (new FormField) ->setName('my_extrafield_2') ->setType('text') ->setLabel($this->l('My extrafield carrier branch 2')) ]; if i replace it with (example): public function hookDisplayAfterCarrier($params) { $this->context->smarty->assign([ 'greetingsFront' => 'Hello Front from MyExtraCarrierBranch !', ]); return $this->display(__FILE__, 'my-front-template.tpl'); } and create one simple my-front-template file. It outputs exactly on the place of the hook this message "Hello....". So it seems that the form (new FormField) that is created here is not created/accepted by Prestashop. as far as i have seen in other modules, there is no need even to create a tpl file for this form. Should be created and displayed by prestashop. So am i wrong, or how should i force creating the input form fields in the front? Link to comment Share on other sites More sharing options...
pl.sabotinov Posted March 1, 2023 Author Share Posted March 1, 2023 I think i found the rerason. Actually it is obvious, but still i just took too much from the example module. So with the function: public function hookDisplayAfterCarrier($params) { return [ (new FormField) ->setName('my_extrafield_1') ->setType('text') //->setRequired(true) ->setLabel($this->l('My extrafield carrier branch 1')), (new FormField) ->setName('my_extrafield_2') ->setType('text') ->setLabel($this->l('My extrafield carrier branch 2')) ]; i am trying to create new field in the form. But here in this Step, where my hook is, there is no html form created by Prestashop. So not possible to create a new field. Would someone please suggest me how can create (easiest method) a simpe form here at this place (after carriers list) with this both fields. I suppose i should also register my module in the hook carrier processing, or order processing, where i should make the insert of these values in the db table. Because there is no function in presta that will do it for this new form i suppose. Link to comment Share on other sites More sharing options...
pl.sabotinov Posted March 10, 2023 Author Share Posted March 10, 2023 There is one last thing that i need some help. If i create a form in a custom template file (template file generated in my module): <form class="clearfix" id="configuration_form" data-url-update="{url entity='order' params=['ajax' => 1, 'action' => 'selectDeliveryOption']}" method="post"> <div class="panel" id="fieldset_0"> <div class="form-wrapper"> <div class="form-group"> <label for="myextrafield_id">{l s='Carrier branch additional Address or Name(option): '}</label> <input type="text" id="my_extrafield_1" name="my_extrafield_1" size="50" maxlength="120" value="" /> <label for="my_extrafield_2">{l s='Carrier branch additional Address or Name(option): '}</label> <input type="text" id="my_extrafield_2" name="my_extrafield_2" size="50" maxlength="120" value="" /> <input type="submit" value="Submit"> </div> </div> </div> </form> Am i able to get the value of the input field: my_extrafield_1 within php file of my module with the Tools::getValue('my_extrafield_1')? Because when i try to do this the value is empty. Of course it depends when is the hook displayHeader executed - only once in beginning or each time when moving trough the order steps? I just want to display the value there to be sure that it is saved and accesible in $_POST array of vars. 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