How do I post some variables to a file using opencart?

筅森魡賤 提交于 2019-12-06 06:57:00

First of all - I do not understand why would You like to post some name and address from checkout/login page as there are no such fields at default, unless You have added them.

Anyway in such a case I would proceed this way - post to a receive() method via AJAX as You do. Here I would save the variables into a session:

public function receive() {
    $this->session->data['guest_name'] = $this->request->post['name'];
    $this->session->data['guest_address'] = $this->request->post['address'];
}

Now in catalog/controller/checkout/guest.php at index method check for that session variables and if set, store the value in the $this->data array for presenting to the template:

if(isset($this->session->data['guest_name'])) { // it is enough to check only for one variable and only if it is set
    $this->data['guest_name'] = $this->session->data['guest_name'];
    $this->data['guest_address'] = $this->session->data['guest_address'];
}

After that You can simply echo these values in Your template (still checking whether exists):

<?php if(isset($guest_name)) { ?>
<div><?php echo $guest_name . ' - ' . $guest_address; ?></div>
<?php } ?>

Now You should be done while avoiding any undefined variable notices...

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