X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Add Field to Contact Us form (https://forum.x-cart.com/showthread.php?t=73532)

ant99 02-05-2016 12:53 PM

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.

meterguy 02-05-2016 01:28 PM

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.

qualiteam 02-07-2016 08:59 PM

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

ant99 02-08-2016 08:40 AM

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.

qualiteam 02-08-2016 11:12 PM

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.

ant99 02-15-2016 01:33 PM

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();
    }
}


ant99 02-15-2016 01:35 PM

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... :)

qualiteam 02-16-2016 12:32 AM

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.

ant99 02-16-2016 12:33 PM

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. :D/

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.

qualiteam 02-16-2016 08:48 PM

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.


All times are GMT -8. The time now is 11:31 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.