Jump to content

Adding attachment to contact form


Recommended Posts

Has this been done? Any information on how to do it would be great.

I would like my user to be able to add and send an attachment

Using this code:

TPL:

>{capture name=path}{l s='Contact'}{/capture}
{include file=$tpl_dir./breadcrumb.tpl}

{l s='Contact us'}

{if isset($confirmation)}

{l s='Your message has been successfully sent to our team.'}
</pre>
<ul>
{l s='Home'}
</ul>
<br>{else}<br><p>{l s='For questions about an order or for information about our products'}.</p>
<br>   {include file=$tpl_dir./errors.tpl}<br>   <form action="{$request_uri|escape:'htmlall':'UTF-8'}" method="post" class="std"><br><br><h3>{l s='Send a message'}</h3>
<br><p>
{l s='Subject'}

{l s='-- Choose --'}
               {foreach from=$contacts item=contact}
{$contact.name|escape:'htmlall':'UTF-8'}
               {/foreach}

</p>
<br><br>       {foreach from=$contacts item=contact}<br><p>
{l s='Description'}{$contact.description|escape:'htmlall':'UTF-8'}</p>
<br>       {/foreach}<br><p>
{l s='Name'}
           <input type="text" id="name" name="name" value="{if isset($smarty.post.name)}{$smarty.post.name|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><p>
{l s='Last Name'}
           <input type="text" id="lastname" name="lastname" value="{if isset($smarty.post.lastname)}{$smarty.post.lastname|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><p>
{l s='Address'}
           <input type="text" id="address" name="address" value="{if isset($smarty.post.address)}{$smarty.post.address|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><p>
{l s='City'}
           <input type="text" id="city" name="city" value="{if isset($smarty.post.city)}{$smarty.post.city|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><p>
{l s='Postal Code'}
           <input type="text" id="postalcode" name="postalcode" value="{if isset($smarty.post.postalcode)}{$smarty.post.postalcode|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><p>
{l s='Region'}
           <input type="text" id="region" name="region" value="{if isset($smarty.post.region)}{$smarty.post.region|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><p>
{l s='Telephone'}
           <input type="text" id="telephone" name="telephone" value="{if isset($smarty.post.telephone)}{$smarty.post.telephone|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><br><p>
{l s='E-mail address'}
           <input type="text" id="email" name="from" value="{if isset($smarty.post.from)}{$smarty.post.from|escape:'htmlall'|stripslashes}{/if}" />
</p>
<br><br><p>
{l s='Message'}
            <textarea id="message" name="message" rows="7" cols="35">{if isset($smarty.post.message)}{$smarty.post.message|escape:'htmlall'|stripslashes}{/if}</textarea>
</p>
<br><p>
           <input type="submit" name="submitMessage" id="submitMessage" value="{l s='Send'}" class="button_large" />
</p>
<br><br></form><br>{/if}

Link to comment
Share on other sites

PHP:

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');

$errors = array();

$smarty->assign('contacts', Contact::getContacts(intval($cookie->id_lang)));

if (Tools::isSubmit('submitMessage'))
{
   if (!($from = Tools::getValue('from')) OR !Validate::isEmail($from))
       $errors[] = Tools::displayError('Invalid e-mail address');

       elseif (!($name = nl2br2(Tools::getValue('name'))))
       $errors[] = Tools::displayError('Name cannot be blank');
       elseif (!($lastname = nl2br2(Tools::getValue('lastname'))))
       $errors[] = Tools::displayError('Last Name cannot be blank');
       elseif (!($address = nl2br2(Tools::getValue('address'))))
       $errors[] = Tools::displayError('Address cannot be blank');
       elseif (!($city = nl2br2(Tools::getValue('city'))))
       $errors[] = Tools::displayError('City cannot be blank');
       elseif (!($postalcode = nl2br2(Tools::getValue('postalcode'))))
       $errors[] = Tools::displayError('Postal Code cannot be blank');
       elseif (!($region = nl2br2(Tools::getValue('region'))))
       $errors[] = Tools::displayError('Region cannot be blank');    
       elseif (!($telephone = nl2br2(Tools::getValue('telephone'))))
       $errors[] = Tools::displayError('Telephone cannot be blank');
   elseif (!($message = nl2br2(Tools::getValue('message'))))
       $errors[] = Tools::displayError('Message cannot be blank');
   elseif (!Validate::isMessage($message))
       $errors[] = Tools::displayError('Invalid message');
   elseif (!($id_contact = intval(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact(intval($id_contact), intval($cookie->id_lang)))))
       $errors[] = Tools::displayError('Please select a contact in the list');
   else
   {
       if (Mail::Send(intval($cookie->id_lang), 'contact', 'Email from '.$_POST['name'], array('{email}' => $_POST['from'], '{message}' => stripslashes($message)), $contact->email))
           $smarty->assign('confirmation', 1);
       else
           $errors[] = Tools::displayError('An error occurred while sending message');
   }
}
$smarty->assign('errors', $errors);

Tools::safePostVars();
$smarty->display(_PS_THEME_DIR_.'contact-form.tpl');
include(dirname(__FILE__).'/footer.php');

?> 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...