Page 1 of 1

Invalid session token when i hit the save button

Posted: Thu Feb 12, 2015 11:29 am
by RijalTanjung
Hello , I'm new here.. i have problem with my module, i have try to hit the submit button, but error has come with INVALID TOKEN SESSION. Please login again.. I don't know why, i see the URL parameter don't have "route=" , just appear like this "http://localhost/opencart/admin/index.p ... =&status=1 " . The controller 'saved' in module folder then all the component saved in 'news' folder.

the code in form and insert function :

Code: Select all


public function insert(){
		$this -> load -> language('news/news');
		$this -> load -> model('news/news');
		
// Warning code skipped

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_news_news->addNews($this->request->post);
 
            $this->session->data['success'] = $this->language->get('text_success');
 
            $this->redirect($this->url->link('module/news', 'token=' . $this->session->data['token'], 'SSL'));
        }
 
        $this->data['breadcrumbs'] = array();
 
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => false
        );
 
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('module/news', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );
 
        $this->data['action'] = $this->url->link('module/news/insert', '&token=' . $this->session->data['token'], 'SSL');
        $this->data['cancel'] = $this->url->link('module/news', '&token=' . $this->session->data['token'], 'SSL');
        $this->data['token'] = $this->session->data['token'];
 
        $this->form();
    }
	
	private function form() {
		$this -> load -> language('news/news');
		$this -> load -> model('news/news');
		$this -> load -> model('localisation/language');
		
// Language code skipped

        $this->data['languages'] = $this->model_localisation_language->getLanguages();
		
		if (isset($this->request->get['news_id'])) {
            $news = $this->model_news_news->getNews($this->request->get['news_id']);
        } else {
            $news = '';
        }
 
        if (isset($this->request->post['news'])) {
            $this->data['news'] = $this->request->post['news'];
        } elseif (!empty($news)) {
            $this->data['news'] = $this->model_news_news->getNewsDescription($this->request->get['news_id']);
        } else {
            $this->data['news'] = '';
        }
 
        if (isset($this->request->post['keyword'])) {
            $this->data['keyword'] = $this->request->post['keyword'];
        } elseif (!empty($news)) {
            $this->data['keyword'] = $news['keyword'];
        } else {
            $this->data['keyword'] = '';
        }
 
        if (isset($this->request->post['status'])) {
            $this->data['status'] = $this->request->post['status'];
        } elseif (!empty($news)) {
            $this->data['status'] = $news['status'];
        } else {
            $this->data['status'] = '';
        }
 
        $this->template = 'news/news_form.tpl';
        $this->children = array(
            'common/header',
            'common/footer'
        );
 
        $this->response->setOutput($this->render());
    }

 
What's wrong with this ? anybody please help me ??? ???

Re: Invalid session token when i hit the save button

Posted: Fri Feb 13, 2015 10:00 pm
by fido-x
For starters - get rid of those spaces!
RijalTanjung wrote:the code in form and insert function :

Code: Select all

public function insert(){
 $this -> load -> language('news/news');
 $this -> load -> model('news/news');
 
// Warning code skipped
and

Code: Select all

 private function form() {
 $this -> load -> language('news/news');
 $this -> load -> model('news/news');
 $this -> load -> model('localisation/language');
 
// Language code skipped
Should be:

Code: Select all

public function insert(){
    $this->load->language('news/news');
    $this->load->model('news/news');
and

Code: Select all

private function form() {
    $this->load->language('news/news');
    $this->load->model('news/news');
    $this->load->model('localisation/language');
If you're trying to build some kind of news/blog module, why not try this. After all, there's no sense in trying to "re-invent the wheel" if it's already been done (and free, even).

Re: Invalid session token when i hit the save button

Posted: Fri Feb 13, 2015 11:56 pm
by RijalTanjung
Thank You for the reply and suggestion, fido-x ! :) i don't know that those space is make invalid session ??? what's your explanation for this ? i hopefull to get a new knowledge from you ;D

But the problem is not fixed, i though the problem is not for those space, because i see the 'route=' parameter has gone.. i don't know why, so i ask to these forum ;)

Re: Invalid session token when i hit the save button

Posted: Sat Feb 14, 2015 4:44 pm
by fido-x
Bearing in mind, this is an OpenCart 2 support area, the code you have provided will not work with OpenCart 2.

Any reference to "$this->data['something']" needs to be replaced with "$data['something"].

The call to the template file is also invalid for OC 2. Replace:

Code: Select all

$this->template = 'news/news_form.tpl';
$this->children = array(
	'common/header',
	'common/footer'
);

$this->response->setOutput($this->render());
with:

Code: Select all

$this->response->setOutput($this->load->view('news/news_form.tpl', $data));