Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Add Field to Contact Us form

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 02-05-2016, 12:53 PM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default Add Field to Contact Us form

I would like to add an optional "Phone Number" field to the Contact Us module in XC5. What is the simplest way to do this?


Thank you.
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #2  
Old 02-05-2016, 01:28 PM
 
meterguy meterguy is offline
 

Newbie
  
Join Date: Sep 2015
Posts: 5
 

Default Re: Add Field to Contact Us form

ant99, I too would like to add fields to the Contact Us page. Lets see what ideas people have.
__________________
Free 5.2.6
Modules: Sales tax, Converge, UPS
Reply With Quote
  #3  
Old 02-07-2016, 08:59 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Add Field to Contact Us form

There is no setting to show the phone number field on the contact page. You can add the field by creating a custom module if this is something that you are OK with.

For a better Contact Us page you may try this module (however, I think it does no have the phone field too):
https://www.x-cart.com/extensions/addons/contact-us-page-by-mightycall.html
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #4  
Old 02-08-2016, 08:40 AM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default Re: Add Field to Contact Us form

Hi Alex, Yes I was wanting to modify the form via a custom module. i am just looking for guidance on the code I would be modifying. I already have a custom theme & module in place I just want to modify the form.

Thanks for your suggestion, but I don't think that module will achieve what we're looking for.
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #5  
Old 02-08-2016, 11:12 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Add Field to Contact Us form

The template that renders the form is this one:
skins/default/en/modules/CDev/ContactUs/contact_us/body.tpl

Instead of editing the template you should inject your new field into the template by adding it into the "contact-us.send.fields" view list.
Please check the skins/default/en/modules/CDev/ContactUs/contact_us/fields/ directory to see how other fields are added to the list.

The form data is collected in this method:
\XLite\Module\CDev\ContactUs\Controller\Customer\C ontactUs::doActionSend()

So, you should decorated this class from your module and add the logic that handles the new field.

Also, you are to decorate the \XLite\Core\Mailer::sendContactUsMessage() method (and associated templates) to get the new field included into e-mails.

I hope this helps.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
ant99 (02-16-2016)
  #6  
Old 02-15-2016, 01:33 PM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default Re: Add Field to Contact Us form

Hi Alex,

Thanks for your insight. I was able to locate and find everything to modify. Looks like all is in the proper place, but I had trouble decorating the class XLite\Core\Mailer

Specifically, the last step I need in place is to over-ride XLite\Module\CDev\ContactUs\Core:sendContactUsMess age()

I need to change the line in bold to point to 'modules/MyModule/ContactUs/message':

XLite\Module\CDev\ContactUs\Core\Mailer.php
PHP Code:
public static function sendContactUsMessage(array $data$email)
    {
        static::
$fromStorage $data['email'];
        
$data['message'] = htmlspecialchars($data['message']);

        static::
register('data'$data);

        static::
compose(
            static::
TYPE_CONTACT_US,
            static::
getSiteAdministratorMail(),
            
$email,
[
b]            'modules/CDev/ContactUs/message',[/b]            
            array(),
            
true,
            \
XLite::ADMIN_INTERFACE
        
);

        return static::
getMailer()->getLastError();
    } 

I have my own body.tpl in the folder (skins/mail/modules/MyModule/ContactUs/message) that would include the extra fields into the email. However, I must be doing something wrong with how I'm decorating the Mailer class.

I'm assuming the file would be here: (/classes/XLite/Module/MyModule/Core/Mailer.php)

But what do I need to include in this file to decorate the class properly?

I tried this:
XLite\Module\MyModule\Core\Mailer.php

PHP Code:
<?php
namespace XLite\Module\MyModule\Core;

/**
 * Mailer
 */
[b]abstract class Mailer extends \XLite\Core\Mailer implements \XLite\Base\IDecorator
[/b]{
    
/**
     * Send contact us message
     *
     * @param array  $data  Data
     * @param string $email Email
     *
     * @return string | null
     */
    
public static function sendContactUsMessage(array $data$email)
    {
        static::
$fromStorage $data['email'];
        
$data['message'] = htmlspecialchars($data['message']);

        static::
register('data'$data);

        static::
compose(
            static::
TYPE_CONTACT_US,
            static::
getSiteAdministratorMail(),
            
$email,
[
b]            'modules/MyModule/ContactUs/message',
[/
b]            array(),
            
true,
            \
XLite::ADMIN_INTERFACE
        
);

        return static::
getMailer()->getLastError();
    }
}


I also tried this:
XLite\Module\MyModule\Core\Mailer.php

PHP Code:
<?php
namespace XLite\Module\MyModule\Core;

/**
 * Mailer
 */
[b]abstract class Mailer extends \XLite\Module\CDev\ContactUs\Core\Mailer implements \XLite\Base\IDecorator
[/b]{
    
/**
     * Send contact us message
     *
     * @param array  $data  Data
     * @param string $email Email
     *
     * @return string | null
     */
    
public static function sendContactUsMessage(array $data$email)
    {
        static::
$fromStorage $data['email'];
        
$data['message'] = htmlspecialchars($data['message']);

        static::
register('data'$data);

        static::
compose(
            static::
TYPE_CONTACT_US,
            static::
getSiteAdministratorMail(),
            
$email,
[
b]            'modules/MyModule/ContactUs/message',
[/
b]            array(),
            
true,
            \
XLite::ADMIN_INTERFACE
        
);

        return static::
getMailer()->getLastError();
    }
}
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #7  
Old 02-15-2016, 01:35 PM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default Re: Add Field to Contact Us form

(sorry, the [b] tags didn't work inside the code lines. Please note that those [b] tags are showing the parts I'm focusing on to modify...
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #8  
Old 02-16-2016, 12:32 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Add Field to Contact Us form

ContactUs module does not create a new class, but modifies the existing one (due to the "implements \XLite\Base\IDecorator" part):
PHP Code:
abstract class Mailer extends \XLite\Core\Mailer implements \XLite\Base\IDecorator { ... } 

Well, technically it does create a new class, but it won't be used anywhere except the inheritance tree for the \XLite\Code\Mailer class.

So, you should decorate \XLite\Code\Mailer class, not \XLite\Module\CDev\ContactUs\Core\Mailer (and thus your first try sounds good to me).

One thing you should to change is the PHPDoc for your class. Since your module can't work without the ContactUs module, you should add the "@LC_Dependencies" tag:
PHP Code:
/**
 * Mailer
 * 
 * @LC_Dependencies ("CDev\ContactUs")
 */
abstract class Mailer extends \XLite\Core\Mailer implements \XLite\Base\IDecorator
{
...


Why did you change the body.tpl template? I believe you don't need to modify it, just add a new template with your field and make it injected into the "contact-us.send.fields" view list by using the @ListChild tag.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote

The following user thanks qualiteam for this useful post:
ant99 (02-16-2016)
  #9  
Old 02-16-2016, 12:33 PM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default Re: Add Field to Contact Us form

Thank you Alex, the dependency is what I was missing. Looks like it's all wrapped into my module perfectly now.

The body.tpl file that I'm modifying looks like this. (it's in the mail templates)

/skins/mail/en/modules/CDev/ContactUs/message/body.tpl
PHP Code:
<p>
  {
getNotificationText():h}
</
p>
<
p>
  <
b>{t(#Name#)}:</b> {data.name}<br />
  
<b>{t(#E-mail#)}:</b> {data.email}<br />
  
<b>{t(#Subject#)}:</b> {data.subject}<br />
</p>
<
p>
  {
data.message:nl2br}
</
p

I don't think I can just inject the new field that I added. Correct? This is why I created a new body.tpl to over-ride the one in the ContactUs module.

Thanks again.
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #10  
Old 02-16-2016, 08:48 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Add Field to Contact Us form

You're right. I though your phrase was about the contact form, not the e-mail itself.
I think replacing the body.tpl for the e-mail is the only possible solution at the moment.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:51 PM.

   

 
X-Cart forums © 2001-2020