【问题标题】:undefined index (opencart)未定义的索引(opencart)
【发布时间】:2014-11-15 13:37:59
【问题描述】:

我正在尝试在 opencart 中添加新的输入文本, 我的观点 payment_method.tpl 我添加了

<label><?php echo $text_comments; ?></label>
<textarea name="comment" rows="8" style="width: 98%;"><?php echo $comment; ?></textarea>

 <label><?php echo $text_referred; ?></label> // My Code
 <input type="text" name="referred" value="<?php echo $referred; ?>" />

在控制器payment_method.tpl我添加了

if (!$json) {
                $this->session->data['payment_method'] = $this->session->data['payment_methods'][$this->request->post['payment_method']];
                $this->session->data['comment'] = strip_tags($this->request->post['comment']);
                $this->session->data['referred'] = $this->request->post['referred']; //My Code
            }   

if (isset($this->session->data['referred'])) {
            $this->data['referred'] = $this->session->data['referred']; //Variable
        } else {
            $this->data['referred'] = '';
        }

在我的模型中 Order.php

$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "',  referred = '" . $this->db->escape($data['referred']) . "',

我的错误日志显示

2014-09-21 12:57:42 - PHP Notice:  Undefined index:  referred in /home/dlars/public_html/tempdir/vqmod/vqcache/vq2-catalog_controller_checkout_payment_method.php on line 212
2014-09-21 12:57:42 - PHP Notice:  Undefined index:  referred in /home/dlars/public_html/tempdir/vqmod/vqcache/vq2-catalog_model_checkout_order.php on line 4

我收集到我视图中的任何内容都没有发布到我的控制器,但是我不确定我可以在哪里定义引用。 我认为使用 OC 在视图中定义的任何内容都已发布到控制器?

请大家帮忙

提前致谢

【问题讨论】:

    标签: php opencart


    【解决方案1】:

    这里的问题很明显。新的 referred 输入未通过 HTTP AJAX 请求传递。这是在不同的模板中引起的 - checkout.tpl。打开它,滚动到最后并搜索这个 JS 回调:

    $('#button-payment-method').live('click', function() {
    

    在这里找到线

    data: $('#payment-method input[type=\'radio\']:checked, #payment-method input[type=\'checkbox\']:checked, #payment-method textarea'),
    

    并将其更改为:

    data: $('#payment-method input[type=\'radio\']:checked, #payment-method input[type=\'checkbox\']:checked, #payment-method textarea, #payment-method input[type=\'text\']'),
    

    现在应该通过 AJAX 请求传递值,并且应该为 referred 索引设置。

    【讨论】:

    • 不错!环顾四周,没有提到任何地方
    猜你喜欢
    • 2016-06-12
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 2012-12-08
    • 2012-09-18
    相关资源
    最近更新 更多