Post by nytevizion » Fri Oct 05, 2012 10:08 am

I used the tutorial from the first page to generate a simple contact form using controller, template and language files. My form has a file upload option; however, I am stumped on how to attach the file to the email and change the content type.


I've listed my controller file. It sends a basic text email, it just doesn't attach the file not does it honor html tags within the body of the email.

Hopefully someone can push me in the right direction.

Code: Select all

<?php
class ControllerInformationSellform extends Controller {
    
	private $error = array();  // <-- add this line right here!
	
	public function index() {
        
		$this->language->load('information/sellform'); //Optional. This calls for your language file
 		

 		
 		$this->data['text_name'] = $this->language->get('text_name');

		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($this->request->post['name']);

			$email_body = '<h1>Name: </h1>' . $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->redirect($this->url->link('information/sellform/success'));
		}

		if (isset($this->error['name'])) {

        	$this->data['error_name'] = $this->error['name'];

    			} else {

        	$this->data['error_name'] = '';

    	}
		
		if (isset($this->error['email'])) {

        	$this->data['error_email'] = $this->error['email'];

    			} else {

        	$this->data['error_email'] = '';

    	}
		
		if (isset($this->error['phone'])) {

        	$this->data['error_phone'] = $this->error['phone'];

    			} else {

        	$this->data['error_phone'] = '';

    	}
		
		if (isset($this->error['enquiry'])) {

        	$this->data['error_enquiry'] = $this->error['enquiry'];

    			} else {

        	$this->data['error_enquiry'] = '';

    	}
		
		if (isset($this->error['file'])) {

        	$this->data['error_file'] = $this->error['file'];

    			} else {

        	$this->data['error_file'] = '';

    	}
		
		if (isset($this->error['captcha'])) {
   
   			$this->data['error_captcha'] = $this->error['captcha'];
   
    			} else {
   
        	$this->data['error_captcha'] = '';
   
    	}
		
		if (isset($this->request->post['name'])) {
   
        	$this->data['name'] = $this->request->post['name'];
   
    			} else {
   
   			$this->data['name'] = '';
   
    	}
		
		if (isset($this->request->post['email'])) {
   
        	$this->data['email'] = $this->request->post['email'];
   
    			} else {
   
   			$this->data['email'] = '';
   
    	}
		
			if (isset($this->request->post['phone'])) {
   
        	$this->data['phone'] = $this->request->post['phone'];
   
    			} else {
   
   			$this->data['phone'] = '';
   
    	}
		
		if (isset($this->request->post['enquiry'])) {
   
        	$this->data['enquiry'] = $this->request->post['enquiry'];
   
    			} else {
   
   			$this->data['enquiry'] = '';
   
    	}
		
		if (isset($this->request->post['file'])) {
   
        	$this->data['file'] = $this->request->post['file'];
			
    	}
		

		
		if (isset($this->request->post['captcha'])) {
   
   			$this->data['captcha'] = $this->request->post['captcha'];
   
    			} else {
   
   			$this->data['captcha'] = '';
   
    	}
		
		
		   
	   	$this->data['action'] = $this->url->link('information/sellform');
		$this->data['store'] = $this->config->get('config_name');
    	$this->data['address'] = nl2br($this->config->get('config_address'));
    	$this->data['telephone'] = $this->config->get('config_telephone');
    	$this->data['fax'] = $this->config->get('config_fax');

 		
        //*$this->document->setTitle($this->language->get('heading_title')); //Optional. Set the title of your web page.
 
        $this->data['breadcrumbs'] = array();
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home'),
            'separator' => false
        );
        $this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('information/sellform'),
            'separator' => $this->language->get('text_separator')
        );
 
        // Text from language file
        $this->data['heading_title'] = $this->language->get('heading_title'); 
        $this->data['text_content']  = $this->language->get('text_content');
		
	   	$this->data['button_continue'] = $this->language->get('button_continue');
		$this->data['heading_title'] = $this->language->get('heading_title');
		
		
		$this->data['text_location'] = $this->language->get('text_location');
		$this->data['text_contact'] = $this->language->get('text_contact');
		$this->data['text_address'] = $this->language->get('text_address');
    	$this->data['text_telephone'] = $this->language->get('text_telephone');
    	$this->data['text_fax'] = $this->language->get('text_fax');

    	$this->data['entry_name'] = $this->language->get('entry_name');
    	$this->data['entry_email'] = $this->language->get('entry_email');
		$this->data['entry_phone'] = $this->language->get('entry_phone');
    	$this->data['entry_enquiry'] = $this->language->get('entry_enquiry');
		$this->data['entry_file'] = $this->language->get('entry_file');
		$this->data['entry_captcha'] = $this->language->get('entry_captcha');
 
        // We call this Fallback system
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/sellform.tpl')) { //if file exists in your current template folder
            $this->template = $this->config->get('config_template') . '/template/information/sellform.tpl'; //get it
        } else {
            $this->template = 'default/template/information/sellform.tpl'; //or get the file from the default folder
        }
 
        //Required. The children files for the page.
        $this->children = array(
            'common/column_left',
            'common/column_right',
            'common/content_top',
            'common/content_bottom',
            'common/footer',
            'common/header'
        );
 
        $this->response->setOutput($this->render());
    }
	
	
	public function success() {
		$this->language->load('information/sellform');

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

      	$this->data['breadcrumbs'] = array();

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

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

    	$this->data['text_message'] = $this->language->get('text_message');

    	$this->data['button_continue'] = $this->language->get('button_continue');

    	$this->data['continue'] = $this->url->link('common/home');

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/success.tpl';
		} else {
			$this->template = 'default/template/common/success.tpl';
		}
		
		$this->children = array(
			'common/column_left',
			'common/column_right',
			'common/content_top',
			'common/content_bottom',
			'common/footer',
			'common/header'
		);
				
 		$this->response->setOutput($this->render());
		
	}


public function captcha() {

    $this->load->library('captcha');

     $captcha = new Captcha();

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

    $captcha->showImage();

}


private function validate() {


    if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {

        $this->error['name'] = $this->language->get('error_name');

    }

    if (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {

        $this->error['email'] = $this->language->get('error_email');

    }
	
	if ((utf8_strlen($this->request->post['phone']) != null)) {
	
    	if ((utf8_strlen($this->request->post['phone']) < 7) || (utf8_strlen($this->request->post['phone']) > 3000) && (utf8_strlen($this->request->post['phone']) != null)) {

         	$this->error['phone'] = $this->language->get('error_phone');

    	}
	}
	
	if ((utf8_strlen($this->request->post['enquiry']) != null)) {
    	if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_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');

    }
    
 
    if (!$this->error) {

    return true;

    } else {

     return false;

    }       

}
}
?>

Newbie

Posts

Joined
Fri Jun 29, 2012 1:49 am

Post by xiaohaizhi » Fri Aug 09, 2013 6:05 pm

Hi Eyechild Can assist why im getting these error upon submitting this vqmod version of this form?

the form is displaying correctly on information page id.

and on the back end the email was successfully sent to admin however it return error after clicking submit button.

Notice: Undefined variable: email_body in /some/directory/vqmod/vqcache/vq2-catalog_controller_information_information.php on line 56
Notice: Undefined index: zone_id in /some/directory/vqmod/vqcache/vq2-catalog_controller_information_information.php on line 65
Notice: Undefined index: name in /some/directory/vqmod/vqcache/vq2-catalog_controller_information_information.php on line 66
Warning: Cannot modify header information - headers already sent by (output started at /some/directory/index.php:104) in /some/directory/vqmod/vqcache/vq2-system_engine_controller.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at /some/directory/index.php:104) in /some/directory/vqmod/vqcache/vq2-system_engine_controller.php

Opencart: v1.5.3.1

Newbie

Posts

Joined
Thu Aug 08, 2013 5:57 pm

Post by xiaohaizhi » Sat Aug 10, 2013 5:52 pm

*update of above error


I've managed to rewrite '$mail->setText' code to solve the email_body undefined variable error.

Thank you.

Newbie

Posts

Joined
Thu Aug 08, 2013 5:57 pm

Post by vinayopencart » Tue Nov 18, 2014 5:26 pm

Hi,

I have a opencart e-commerce website, for this website i have used VQMOD models and Custom plugins, Once i click the home menu of my website the following url http://Domainname/?route=common/home is obtained,
But i need the above url to be a SEO friendly url as http://Domainname/home,
I just tried to fix SEO friendly url opencart models in my website, but it's not working, kindly suggest me to resolve this issue.

Newbie

Posts

Joined
Tue Nov 18, 2014 5:09 pm

Post by yl56661 » Thu Nov 27, 2014 9:19 pm

Hi, EyeChildm

Thanks for your tutorial. I have followed your instructions, create control file, language file and form file. When I click submit button, it takes me to
http://vb11.atc08.com/=%22http://vb11.a ... enquiry%22

and gives me:
Not Found
The requested URL /="http://vb11.atc08.com/index.php was not found on this server.
Apache Server at vb11.atc08.com Port 80


Please advise where could be wrong.

Regards

Yuwan

Newbie

Posts

Joined
Thu Nov 27, 2014 7:34 pm

Post by w-fa » Wed Jun 24, 2015 12:20 pm

Hi,
How can I do this tutorial for opencart 2.x.x? Is there anyone to help me?

Newbie

Posts

Joined
Thu May 14, 2015 2:38 pm

Post by gerstavros » Mon Jun 19, 2017 2:59 am

w-fa wrote:
Wed Jun 24, 2015 12:20 pm
Hi,
How can I do this tutorial for opencart 2.x.x? Is there anyone to help me?
Anybody managed to make it work on opencart 2.x? I m trying this 2 days now, nothing works properly.

Newbie
Online

Posts

Joined
Mon Apr 04, 2016 12:44 am

Post by IP_CAM » Mon Jun 19, 2017 3:35 am

something like this could help!
Ernie
---
Contact Form - Upload File OC 1.5
https://www.opencart.com/index.php?rout ... n_id=11514
---
Contact Page File Upload OC 1.5 - 2
https://www.opencart.com/index.php?rout ... n_id=22005
---
Contact Form - Upload File OC 2
https://www.opencart.com/index.php?rout ... n_id=30591

Ernie's OpenShop 1.75 with responsive Bootstrap Themes:
http://www.bigmax.ch - http://www.hitline.info - http://www.openshop.li
Image


User avatar
Newbie

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: maxfreelance and 66 guests