未定义的索引(opencart)

时间:2014-09-21 13:24:47

标签: php opencart

我试图在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在视图中定义了什么,它被发布到控制器?

有人请帮忙

提前致谢

1 个答案:

答案 0 :(得分:0)

这里的问题很明显。新的引用输入不通过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索引设置。