【问题标题】:Pass variables from a form in a smarty tpl to a controller on form submit将变量从 smarty tpl 中的表单传递到表单提交时的控制器
【发布时间】:2017-02-09 10:32:30
【问题描述】:

我在 tpl 文件中有一个表单:

<form action="{$link->getModuleLink('virtual_pos', 'validation', [], true)|escape:'html'}" method="post"> 
  ... 
</form>

在提交时,我想从表单中获取所有变量并将它们传递给控制器​​“验证”。

我不想使用任何 JS。这是一个商店的支付模块。

我该怎么做?

【问题讨论】:

    标签: php forms model-view-controller prestashop-1.6


    【解决方案1】:

    我在另一个帖子中找到了解决方案。

    创建控制器的链接后,您可以在空数组参数中填充所需的变量:

    <form action="{$link->getModuleLink('virtual_pos', 'validation', ['id'=>$cart_id], true)|escape:'html'}" method="post">
    

    然后在控制器中就可以通过超全局获取数据了

    $id_from_form_submit = $GET['id'];
    

    如果您知道任何其他选项,请告诉我。

    【讨论】:

    • $id_from_form_submit = $_GET['id'];* 你错过了_
    【解决方案2】:

    在你的模块中创建一个文件 controllers/front/validation.php。 你需要一个类:

    class virtual_posValidationModuleFrontController extends ModuleFrontController
    {
        public function postProcess()
        {
              /* where you get the values and validate the order */
        }
    
        public function initContent()
        {
            parent::initContent();
            /* where you set data for a last page order confirmation */
        }
    }
    

    你已经创建了吗?

    【讨论】:

    • 我正在通过重定向到订单确认来处理这个问题。因为我正在等待 AJAX 调用从 API 返回。 Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module-> currentOrder.'&key='.$customer->secure_key);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 2016-12-12
    相关资源
    最近更新 更多