- 浏览: 13624530 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
magento 添加上传功能 Adding upload field in contact form and send as attachment
Introduction
Nowadays most of the clients wants extra fields in contacts form of
magento to fulfill their requirements. And adding custom fields other
than upload field (for example: text, textarea, select etc) in contact
form are easy in the sense you can easily include the field values in
contact email template.
But adding upload field can be trickier as you have to process the file upload operation and attach it with your email contents.
Steps
1. Modify the contact form template
You need to modify the contact form template file:
app/design/frontend/[your-interface]/[your-theme]/template/contacts/form.phtml:
a>
Add enctype=”multipart/form-data” in <form> element as:
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" enctype="multipart/form-data">
b> Add file upload field below ‘Comment’ field (or anywhere you want) as:
<li> <label for="attachment"><?php echo Mage::helper('contacts')->__('Attachment') ?></label> <div class="input-box"> <input name="MAX_FILE_SIZE" type="hidden" value="2000000" /> <input name="attachment" id="attachment" class="input-text" type="file" /> </div> </li>
2. Create controller class for processing file upload
Next step is to override the Mage_Contacts_IndexController
class.
For this you need to create a custom module. For tutorial purpose I am
assuming Namespace to be ‘MagePsycho’ and Module to be ‘Customcontact’.
a> Add xml override code in your module’s config.xml as:
<frontend> <routers> <contacts> <args> <modules> <magepsycho_customcontact before="Mage_Contacts">MagePsycho_Customcontact</magepsycho_customcontact> </modules> </args> </contacts> </routers> </frontend>
b>
Create your custom controller
Create controller file in your module dir as: app/code/local/MagePsycho/Customcontact/controllers/IndexController.php
and copy the following code:
<?php require_once Mage::getModuleDir('controllers', 'Mage_Contacts') . DS . 'IndexController.php'; class MagePsycho_Contactspro_IndexController extends Mage_Contacts_IndexController { public function postAction() { $post = $this->getRequest()->getPost(); if ( $post ) { $translate = Mage::getSingleton('core/translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); try { $postObject = new Varien_Object(); $postObject->setData($post); $error = false; if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) { $error = true; } if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) { $error = true; } if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) { $error = true; } if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) { $error = true; } /**************************************************************/ $fileName = ''; if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') { try { $fileName = $_FILES['attachment']['name']; $fileExt = strtolower(substr(strrchr($fileName, ".") ,1)); $fileNamewoe = rtrim($fileName, $fileExt); $fileName = preg_replace('/\s+', '', $fileNamewoe) . time() . '.' . $fileExt; $uploader = new Varien_File_Uploader('attachment'); $uploader->setAllowedExtensions(array('doc', 'docx','pdf')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $path = Mage::getBaseDir('media') . DS . 'contacts'; if(!is_dir($path)){ mkdir($path, 0777, true); } $uploader->save($path . DS, $fileName ); } catch (Exception $e) { $error = true; } } /**************************************************************/ if ($error) { throw new Exception(); } $mailTemplate = Mage::getModel('core/email_template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ /**************************************************************/ //sending file as attachment $attachmentFilePath = Mage::getBaseDir('media'). DS . 'contacts' . DS . $fileName; if(file_exists($attachmentFilePath)){ $fileContents = file_get_contents($attachmentFilePath); $attachment = $mailTemplate->getMail()->createAttachment($fileContents); $attachment->filename = $fileName; } /**************************************************************/ $mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($post['email']) ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT), null, array('data' => $postObject) ); if (!$mailTemplate->getSentSuccess()) { throw new Exception(); } $translate->setTranslateInline(true); Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.')); $this->_redirect('*/*/'); return; } catch (Exception $e) { $translate->setTranslateInline(true); Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later')); $this->_redirect('*/*/'); return; } } else { $this->_redirect('*/*/'); } } }
3> There you go.
Try to attach file and submit the contact form, you will get that file as attachment in contact email.
[Snapshots]
Hope this helps you.
Happy E-Commerce!
来源: http://www.blog.magepsycho.com/adding-upload-field-in-contact-form-and-send-as-attachment/
发表评论
-
Magento: 后台显示图片不能找到 Image file was not found on product tab
2016-08-30 02:22 2879I was uploading some images f ... -
理解WordPress的PingBack和TrackBack
2016-08-26 02:21 5666pingback和trackback的功 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(四)
2016-06-07 11:40 978自上一篇之后,5天过去了,这篇文章总算是挤出来了... 其实 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(三)
2016-06-07 11:41 1997原则上WDCP安装好了,就可以直接使用了,FTP、MySQL ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(二)
2016-06-07 01:33 946上一篇讲到,主机正常运转了。但是此时如果直接访问公网IP是 ... -
零基础 Amazon Web Services (AWS) 入门教程图文版(一)
2016-06-07 01:31 21544现在小站唯一的流量都靠AWS这个关键词了,刚好要用AWS重新 ... -
零基础 Amazon Web Services (AWS) 入门教程 (列表)
2016-06-07 01:32 2030在 Amazon Web Services 上托 ... -
Magento 1.9:新订单通知 Admin Order Notifier
2016-06-02 02:48 798Here is a little Mag ... -
Magento 1.9.X 系列教程
2016-05-14 02:44 2242Magento安装下载教学: Magento教程 1 ... -
Magento: 产品页面下jquery change函数失效 Call javascript function onchange product option
2016-05-05 06:39 1690明显的原因是change函数跟magento默认的oncha ... -
Magento: 判断是否为手机浏览 Optimise Web's Mobile Detect Class for Magento
2016-04-29 07:01 1118项目地址:Optimise Web's Mobile Det ... -
Magento: Gird 和 form 区域 Module Development Series – Magento Admin Module
2016-04-28 02:39 632In this tutorial, we are goi ... -
Magento: addAttributeToFilter 和 addFieldToFilter 的区别 Difference between addAttri
2016-04-28 02:34 980addAttributeToFilter is use ... -
Magento: 后台获取menu链接 Getting the admin panel urls
2016-04-28 02:34 732The url for customer page in t ... -
Magento : 调用文件上传 upload file frontend
2016-04-27 01:25 1315bool mkdir ( string $pathname ... -
Magento: 自定义用户登录导向页面 Redirect Customer to Previous Page After Login
2016-04-26 02:45 1814Configuration Settings – L ... -
Magento: 代替flash上传 How to disable Flash uploader in Magento (product images and
2016-04-06 05:04 10831. 替换产品页flash上传按钮 - 使用 Du ... -
Magento: 在客户账户中添加自定义链接 My Account Add Link
2016-04-05 14:05 1193This extension add new link an ... -
Magento: 根据产品属性加载产品信息 Load A Category or Product by an Attribute
2016-03-26 01:35 894Load a Product by ID <?ph ... -
Magento模块开发之数据库SQL操作方法说明
2016-03-26 01:31 1287今天主要来看Magento中的Mysql4/Resource ...
相关推荐
Magento No Flash Upload插件,替换原有的Flash上传
magento 批量上传模板,csv格式,里面有解释和实例
magento批量上传多图、添加自定义属性插件,包含1.4和1.5+的版本
这个文件用于magento 批量上传产品后,前端只显示产品主图不能显示详细图片的bug. 也可用于批量上传商品的尺码或属性。注意: media_img.csv和 attrib.csv这两个文件只能放在tool目录里面。这个工具测试了magento ...
Magento1.7测试可用 批量产品多图上传 包含上传样本
magento 批量上传产品,多图,自定义属性
magento程序添加多个表运费,可以自行设置运费计算公式
Magento 2 Beginners Guide by Gabriel Guarino English | 14 Mar. 2017 | ASIN: B01MS81BQX | 442 Pages | AZW3 | 31....He is also a moderator in Magento forums, and he is a frequent speaker at Magento events.
magento 批量上传产品插件,支持最新magento1.5 1.6,支持批量上传多图,自定义选项
magento 功能与结构的介绍 英文版
magento2添加51track物流功能 1:后台添加51track密钥 2:对接51track物流接口 3:实现添加物流单号自动提交到51track
magento数据传输及功能介绍
Magento的功能目录讲解资料: 市场营销工具 分析与报告 搜索引擎优化 站点管理 目录管理 浏览目录 浏览商品 移动商务 国际支持 结账 配送 支付 客户服务 客户账户 订单管理
此插件功能可以在后台添加magento的客户属性已经客户地址属性,已在1.8.1测试,正常安装使用。
NULL 博文链接:https://justcoding.iteye.com/blog/2100394
Chapter 1, Installing Magento 2 on Apache and NGINX, is a totally different ballgame compared to Magento 1. Where Magento 1 could be installed through FTP or SSH, Magento 2 is installable only via the...
NULL 博文链接:https://hudeyong926.iteye.com/blog/1608792
Magento2的客户和地址表单字段经理 快速轻松地从管理员订单创建和客户帐户中删除不需要的表单字段,默认情况下是magento或其他第三方扩展添加的之后(创建管理订单)特征从以下内容中删除不需要的表单字段: 管理员...
magento1.4 适用的多图上传插件 直接把app目录覆盖即可