Opencart Module Structure Part 2


language->load('information/contact');

$this->document->title = $this->language->get(‘heading_title’);

if (($this->request->server[‘REQUEST_METHOD’] == ‘POST’) && $this->validate()) {

//call your function here ex. i’m create function addData($data)
$this->addData($$this->request->post);
$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’]);
$mail->setSubject(sprintf($this->language->get(’email_subject’), $this->request->post[‘name’]));
$mail->setText(strip_tags(html_entity_decode($this->request->post[‘enquiry’], ENT_QUOTES, ‘UTF-8’)));
$mail->send();

$this->redirect(HTTPS_SERVER . ‘index.php?route=information/contact/success’);
}
………………………………..
………………………………..
//create your function
private function addData($data){
$this->db->query(“INSERT INTO ” . DB_PREFIX . “contact SET name = “.$this->db->escape($data[‘name’].”, email = “.$this->db->escape($data[’email’].”,enquiry = “.$this->db->escape($data[‘enquiry’].”, data_added = NOW()”);

}
}
?>

code for create your database.

CREATE TABLE `contact` (
`contact_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
`email` VARCHAR( 96 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
`enquiry` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
`date_added` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE = MYISAM ;

Don't be shellfish...Share on FacebookTweet about this on TwitterShare on Google+Digg thisPin on PinterestShare on Reddit
Post Tagged with , ,

2 Responses so far.

  1. ติดแก๊ส พูดว่า:

    ขอบคุณมากครับ เป็นประโยชน์มากๆ

  2. now sim card พูดว่า:

    I’m really enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Excellent work!

ใส่ความเห็น

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องที่ต้องการถูกทำเครื่องหมาย *