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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With