undefined index (opencart)

偶尔善良 提交于 2020-01-07 04:33:06

问题


I'm trying to add a new input text in opencart, my view payment_method.tpl I added

<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; ?>" />

In Controller payment_method.tpl I added

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
            }   

and

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

In My model 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']) . "',

My error logs show

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

I gather whatever is on my view isn't being posted to my controller, however I'm not sure where else I can define referred. I thought with OC whatever is defined inside the view, it's posted to the controller?

Someone please help

Thanks in advance


回答1:


The problem here is obvious. The new referred input is not passed via HTTP AJAX request. This is caused in a different template - checkout.tpl. Open it up, scroll to the end and search for this JS callback:

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

Here find the line

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

and change it to:

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

Now the value should be passed via AJAX request and should be set for the referred indexes.



来源:https://stackoverflow.com/questions/25959661/undefined-index-opencart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!