Post by Kobra kennedy » Mon May 24, 2021 10:36 pm

Follow up to this post from the Opencart 1.5.+ Forum:
viewtopic.php?f=20&t=85937
Not working. Who can help in 2021

New member

Posts

Joined
Mon May 17, 2021 7:54 pm

Post by OSWorX » Mon May 24, 2021 10:37 pm

Kobra kennedy wrote:
Mon May 24, 2021 10:36 pm
Not working. Who can help in 2021
Which OpenCart version are you using?

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Kobra kennedy » Tue May 25, 2021 6:14 am

I am using Version 3.0.3.7.

New member

Posts

Joined
Mon May 17, 2021 7:54 pm

Post by straightlight » Tue May 25, 2021 10:58 am

Followed is the updated code for recent OC versions regarding the information sellform extension posted from the OP user on the first post:

Code: Select all

<?php
class ControllerInformationSellform extends Controller {    
	private $error = array();
	
	public function index() {        
		$this->load->language('information/sellform'); 
		
 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
   			$mail = new Mail();
  			$mail->protocol = $this->config->get('config_mail_protocol');
   			$mail->parameter = $this->config->get('config_mail_parameter');
   			$mail->hostname = $this->config->get('config_smtp_host');
   			$mail->username = $this->config->get('config_smtp_username');
   			$mail->password = $this->config->get('config_smtp_password');
   			$mail->port = $this->config->get('config_smtp_port');
   			$mail->timeout = $this->config->get('config_smtp_timeout');            
   			$mail->setTo($this->config->get('config_email'));			
   			$mail->setFrom($this->request->post['email']);
   			$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
			
			$email_body = 'Name: ' . $this->request->post['name'] . "\n\r";
   			$email_body .= 'Phone: ' . $this->request->post['phone'] . "\n\r";
   			$email_body .= 'Email: ' . $this->request->post['email'] . "\n\r";
   			$email_body .= 'Comments: ' . $this->request->post['enquiry'] . "\n\r";				
         
   			$mail->setSubject(sprintf("Sell my Watch or Jewelry Request from Website", $this->request->post['name']));
   			$mail->setText(strip_tags(html_entity_decode($email_body, ENT_QUOTES, 'UTF-8')));
         	$mail->send();

        	$this->response->redirect($this->url->link('information/sellform/success'));
		}

		if (isset($this->error['name'])) {
        	$data['error_name'] = $this->error['name'];
    	} else {
        	$data['error_name'] = '';
    	}
		
		if (isset($this->error['email'])) {
        	$data['error_email'] = $this->error['email'];
    	} else {
        	$data['error_email'] = '';
    	}
		
		if (isset($this->error['phone'])) {
        	$data['error_phone'] = $this->error['phone'];
    	} else {
        	$data['error_phone'] = '';
    	}
		
		if (isset($this->error['enquiry'])) {
        	$data['error_enquiry'] = $this->error['enquiry'];
    	} else {
        	$data['error_enquiry'] = '';
    	}
		
		if (isset($this->error['file'])) {
        	$data['error_file'] = $this->error['file'];
    	} else {
        	$data['error_file'] = '';
    	}
		
		if (isset($this->error['captcha'])) {   
   			$data['error_captcha'] = $this->error['captcha'];   
    	} else {   
        	$data['error_captcha'] = '';   
    	}
		
		if (isset($this->request->post['name'])) {   
			$data['name'] = $this->request->post['name'];   
    	} else {   
   			$data['name'] = '';   
    	}
		
		if (isset($this->request->post['email'])) {   
        	$data['email'] = $this->request->post['email'];   
    	} else {   
   			$data['email'] = '';   
    	}
		
		if (isset($this->request->post['phone'])) {   
        	$data['phone'] = $this->request->post['phone'];   
    	} else {   
   			$data['phone'] = '';   
    	}
		
		if (isset($this->request->post['enquiry'])) {   
        	$data['enquiry'] = $this->request->post['enquiry'];   
    	} else {   
   			$data['enquiry'] = '';   
    	}
		
		if (isset($this->request->post['file'])) {   
        	$data['file'] = $this->request->post['file'];			
    	}
		
		if (isset($this->request->post['captcha'])) {   
   			$data['captcha'] = $this->request->post['captcha'];   
    	} else {   
   			$data['captcha'] = '';   
    	}				
		   
	   	$data['action'] = $this->url->link('information/sellform');
		
		$data['store'] = $this->config->get('config_name');
    	$data['address'] = nl2br($this->config->get('config_address'));
    	$data['telephone'] = $this->config->get('config_telephone');
    	$data['fax'] = $this->config->get('config_fax');
 
        $data['breadcrumbs'] = array();
		
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home')
        );
		
        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('information/sellform')
        ); 
  
        $data['column_left'] = $this->load->controller('common/column_left');
		$data['column_right'] = $this->load->controller('common/column_right');
		$data['column_top'] = $this->load->controller('common/column_top');
		$data['column_bottom'] = $this->load->controller('common/column_bottom');
		$data['footer'] = $this->load->controller('common/footer');
		$data['header'] = $this->load->controller('common/header');
		
        $this->response->setOutput($this->load->view('information/sellform', $data));
    }
	
	
	public function success() {
		$this->load->language('information/sellform');

		$this->document->setTitle($this->language->get('heading_title')); 

      	$data['breadcrumbs'] = array();

      	$data['breadcrumbs'][] = array(
        	'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home')
      	);

      	$data['breadcrumbs'][] = array(
        	'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('information/sellform')
      	);	
		
    	$data['continue'] = $this->url->link('common/home');

		$data['column_left'] = $this->load->controller('common/column_left');
		$data['column_right'] = $this->load->controller('common/column_right');
		$data['content_top'] = $this->load->controller('common/content_top');
		$data['content_bottom'] = $this->load->controller('common/content_bottom');
		$data['footer'] = $this->load->controller('common/footer');
		$data['header'] = $this->load->controller('common/header');
				
 		$this->response->setOutput($this->load->view('common/success', $data));		
	}


	public function captcha() {
		$this->load->library('captcha');

		$captcha = new Captcha();

		$this->session->data['captcha'] = $captcha->getCode();

		$captcha->showImage();
	}


	protected function validate() {
		if ((strlen($this->request->post['name']) < 3) || (strlen($this->request->post['name']) > 32)) {
			$this->error['name'] = $this->language->get('error_name');
		}

		if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
			$this->error['email'] = $this->language->get('error_email');
		}
		
		if ((strlen($this->request->post['phone']) != null)) {	
			if ((strlen($this->request->post['phone']) < 7) || (strlen($this->request->post['phone']) > 3000) && (strlen($this->request->post['phone']) != null)) {
				$this->error['phone'] = $this->language->get('error_phone');
			}
		}
		
		if ((strlen($this->request->post['enquiry']) != null)) {
			if ((strlen($this->request->post['enquiry']) < 10) || (strlen($this->request->post['enquiry']) > 3000) && $this->request->get['information_id'] == 10) {
				$this->error['enquiry'] = $this->language->get('error_enquiry');
			}
		}
			  
		if (!isset($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
			$this->error['captcha'] = $this->language->get('error_captcha');
		}
		
		return !$this->error;
	}
}

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: SohBH and 396 guests