Reputation: 89
I'm building an opencart module for my site and have a page that I need a 'refresh' button for and a 'continue' button, where I POST to either itself (in the case of the 'refresh' button or to bespoke2.php with the 'continue' button. I've added the controller and views below. Unfortunately when the continue button is clicked I get redirected to the correct page however the POST variables don't come with it. The refresh button works well. Can anyone tell me where I might be going wrong, I've spent hours playing around with it and have searched the forum and google haven't come up with much?
This is the 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
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 controller bespoke2.php
$this->data['input_width'] = ($this->request->post['size_width']);
The redirect seems to not take the POST across? Any help much appreciated.
Upvotes: 6
Views: 3073
Reputation: 1458
Open
/catalog/controller/account/register.php
Change
$this->redirect($this->url->link('account/customregister', '', 'SSL'));
If some time you have pass with this type
$this->response->redirect($this->url->link('product/product', 'product_id=50', ''));
Upvotes: 0
Reputation: 1670
Assuming you have jquery available (which you should have with a default opencart install) you could use the following (add it to the end of the view) to update the '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>
Upvotes: 2
Reputation: 1670
No, I don't think the redirect will 're-POST' the form variables. A quick fix might be to manually add the variable into the query string of the redirect.
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 could retrieve it in bespoke2.php as follows:
$this->data['input_width'] = $this->request->get['size_width'];
If you don't think that's particularly satisfactory I'd look into manually posting the data via ajax direct to the correct controller rather than redirecting.
Upvotes: 0
Reputation: 3
OpenCart uses session data with redirects like the success messages eg. This might work for your situation as well.
$this->session->data['input_width'] = $this->request->post['size_width'];
Upvotes: 0