问题
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