Opencart redirection and publishing

I am creating an opencart module for my site and have a page for which I need the Refresh button and the continue button, where I POST either myself (in the case of the Refresh button or to bespoke2.php with the continue button. I added a controller and views below. Unfortunately, when the Continue button is clicked, I am redirected to the correct page, however the POST variables do not come with it. The refresh button works well. Can someone tell me where I can go wrong, I spent hours playing with him and looking for a forum, but google didn’t come up with a lot?

This is form.php

<form name="frm" method="POST" action=""> <input type="text" name="size_width"> <input type="submit" name="submit1" class= "button" Value="<?=$button_continue?>" /> <input type="submit" name="submit2" class= "button" Value="<?=$button_refresh?>" /> 

This is the controller.php file

 if (isset($this->request->post['submit1'])) { $this->response->redirect($this->url->link('module/bespoke2')); } elseif (isset($this->request->post['submit2'])) { $this->data['input_width'] = ($this->request->post['size_width']); else{} 

This is the code for the bespoke2.php controller

 $this->data['input_width'] = ($this->request->post['size_width']); 

Does redirecting seem to not tolerate POST? Any help is greatly appreciated.

+6
source share
4 answers

Assuming you have jquery (which you should have with the default opencart setting), you can use the following (add it to the end of the view) to update 'url_to_submit_to' before submitting.

 <script> $("input[name=submit1]").click(function(event) { event.preventDefault(); $('form[name=frm]').attr('action', '/url_to_submit_to').submit(); }); </script> 
+2
source

No, I don’t think the redirect will be “re-POST” form variables. A quick fix might be to manually add the variable to the redirect request string.

 if (isset($this->request->post['submit1'])) { $this->response->redirect($this->url->link('module/bespoke2?size_width=' . $this->request->post['size_width'])); } elseif (isset($this->request->post['submit2'])) { $this->data['input_width'] = $this->request->post['size_width']; else { } 

then you can get it in bespoke2.php as follows:

 $this->data['input_width'] = $this->request->get['size_width']; 

If you do not think that is particularly satisfactory, I would consider the option of manually sending data via ajax directly to the correct controller, rather than redirecting.

0
source

OpenCart uses redirected session data, such as success messages. This may work for your situation.

 $this->session->data['input_width'] = $this->request->post['size_width']; 
0
source

Open

 /catalog/controller/account/register.php 

Edit

 $this->redirect($this->url->link('account/customregister', '', 'SSL')); 

If you spend some time with this type

 $this->response->redirect($this->url->link('product/product', 'product_id=50', '')); 
0
source

Source: https://habr.com/ru/post/984127/


All Articles