Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重定向并在opencart中发布_Php_Html_Opencart - Fatal编程技术网

Php 重定向并在opencart中发布

Php 重定向并在opencart中发布,php,html,opencart,Php,Html,Opencart,我正在为我的站点构建一个opencart模块,有一个页面需要一个“刷新”按钮和一个“继续”按钮,在这里我可以发布到任意一个页面(对于“刷新”按钮或使用“继续”按钮访问bespoke2.php,我在下面添加了控制器和视图。不幸的是,当单击“继续”按钮时,我被重定向到正确的页面,但是POST变量没有随它一起出现。刷新按钮工作正常。有人能告诉我哪里可能出错吗,我已经知道了。)在新台币上玩了几个小时,搜索过论坛,而谷歌没有找到多少 这是form.php <form name="frm" metho

我正在为我的站点构建一个opencart模块,有一个页面需要一个“刷新”按钮和一个“继续”按钮,在这里我可以发布到任意一个页面(对于“刷新”按钮或使用“继续”按钮访问bespoke2.php,我在下面添加了控制器和视图。不幸的是,当单击“继续”按钮时,我被重定向到正确的页面,但是POST变量没有随它一起出现。刷新按钮工作正常。有人能告诉我哪里可能出错吗,我已经知道了。)在新台币上玩了几个小时,搜索过论坛,而谷歌没有找到多少

这是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?>" />
这是控制器bespoke2.php的代码

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

重定向似乎没有让帖子被接受?非常感谢任何帮助。

不,我认为重定向不会“重新发布”表单变量。一个快速解决方法可能是手动将变量添加到重定向的查询字符串中

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 { }
然后您可以在bespoke2.php中检索它,如下所示:

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

如果您不认为这特别令人满意,我会考虑通过ajax将数据直接手动发布到正确的控制器,而不是重定向。

OpenCart使用会话数据和重定向,例如成功消息。 这可能也适用于您的情况

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

假设您有可用的jquery(默认的opencart安装应该有jquery),您可以使用以下命令(将其添加到视图的末尾)在提交之前更新“url\u to\u submit\u to”

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

$(“输入[name=submit1]”。单击(函数(事件){
event.preventDefault();
$('form[name=frm]')。attr('action','/url_to_submit_to')。submit();
});
打开

改变

$this->redirect($this->url->link('account/customregister', '', 'SSL'));
如果有一段时间你已经通过了这种类型

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

唯一的问题,也是一个小问题,就是有很多post变量要添加到这个中。我只展示了一个来简化这个例子,所以我希望不必手动操作……我还设法使用临时标题使用重定向进行post,但是这似乎不希望通过Opencart工作。你可以使用foreach loop循环通过
$this->request->post
来构建查询字符串,但我认为底线是您试图有条件地将一个表单发布到两个不同的URL,这并不是它们真正的工作方式,因此您所做的任何事情都会有点麻烦……另一种可能是使用javascript或jquery来更新提交前表单的action属性,以便根据按下的按钮将其提交到不同的url。我添加了一个新的答案,说明如何在提交之前使用jquery更新表单提交到的url。我添加了此属性,它将帖子发送到下一页,效果很好。感谢帮助。我不完全确定你在这里的意思,你想让我更改系统文件以添加到“response->”注释中吗?如果是,这有什么作用?
$this->redirect($this->url->link('account/customregister', '', 'SSL'));
$this->response->redirect($this->url->link('product/product', 'product_id=50', ''));