Jump to content

Recommended Posts

Posted

Hi,

I am trying to add additional fields to the contact form.  I can get them to show up in the contact form, but when it is sent I the email does not include the  fields I just added.  Here is an example of what I have done.  Any ideas how I can receive the information in the email?   Thanks in advance.

 

/classes/cubecart.class.php  Line 1431  in the private function _contact() {

 

 

$mailer->addReplyTo($_POST['contact']['email'], strip_tags($_POST['contact']['name']));

     $mailer->Subject = html_entity_decode(strip_tags($_POST['contact']['subject']),ENT_QUOTES);

     $mailer->Body  = sprintf($GLOBALS['language']->contact['email_content'], $_POST['contact']['name'], $_POST['contact']['email'], $department, html_entity_decode(strip_tags($_POST['contact']['enquiry']),ENT_QUOTES));

        $mailer->Shiptoname    = strip_tags($_POST['contact']['shipto_name']);

 

         $mailer->shiptoaddress1     = $_POST['contact']['shipto_address1'];

 

           $mailer->shiptoaddress2   = $_POST['contact']['shipto_address2'];

 

          $mailer->shipto_town         = $_POST['contact']['shipto_town'];

 

            $mailer->shipto_state       = $_POST['contact']['shipto_state'];

 

           $mailer->shipto_country   = $_POST['contact']['shipto_country'];

 

             $mailer->shipto_postalcode          = $_POST['contact']['shipto_postalcode'];

 

             $mailer->shipto_other     = $_POST['contact']['shipto_other'];

 

 

foreach ($GLOBALS['hooks']->load('class.cubecart.contact.mailer') as $hook) include $hook;

// Send

 

Added this to the language/en-US.xml  ( I put all my edits in this file – put all from the above  /classes/cubecart.class.php )

 

<group name="email_en">

<string name="email_macro_shipto_address1"><![CDATA[The first ship to address of the customer asking for an international shipping quote.]]></string>

<string name="shipto_address1"><![CDATA[Ship to Address1]]></string>

   </group>

 

modified the skin/content.contact.php by adding the following - put all from the above  /classes/cubecart.class.php

 

 

   <p>{$LANG.common_en.intl_ship} </p>

   <div class="row">

                              <div class="small-12 columns">

      <div class="row">

<div class="large-3 columns"><label for="shipto_address1" class="t5 bold right inline show-for-medium-up">{$LANG.email_en.shipto_address1}</label></div>

<div class="small-12 large-8 left columns">

<input type="text" name="contact[shipto_address1]" id="shipto_address1" value="{$MESSAGE.shipto_address1}"placeholder="Shipping Address 1"></div>

                                             </div></div>

  </div>

Posted

Edit your content.contact.php file. At the very bottom put {DEBUG}.

Run your contact form - a popup should show with all the information about what data is available at that moment.

Keep the popup, but delete the {DEBUG}, so your customers don't see it.

@bsmither is the one who always helps me with this kind of thing, so I'm not good at spotting how to use the debug info. But hopefully you can search through it to see if any of the fields you have tried to add are showing up as available.

Posted

According to the {DEBUG} my fields are available, if I'm reading it right.

I did get the following in my FTP error log: 

[12-Jun-2017 16:12:30 UTC] PHP Parse error:  syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/claudias/public_html/classes/cubecart.class.php on line 1434

Any suggestions?

By the by .... where is bsmithers?

Posted

Well that would have been helpful to show you line 1434 wouldn't it.  LOL  Here it is

    $mailer->Shiptoname    = strip_tags($_POST['contact']['shipto_name']);

Posted (edited)

I see nothing wrong with that statement. So, I would like to see the three statements just before it.

Oh, I see them in the top post.

I see nothing wrong with them either.

Edited by bsmither
Posted

Trying to compare your code with the existing code for any differences at all. I did see that there is not a space before placeholder. Doesn't seem important, but who knows with code.

value="{$MESSAGE.shipto_address1}"placeholder

 

Posted

If the line number reported has a problem, then a means of determining where in the line this happens can be done this way:

Split the line. PHP does not generally care about whitespace:

Change:
$mailer->Shiptoname = strip_tags($_POST['contact']['shipto_name']);

To:
$mailer->Shiptoname
=
strip_tags(
 $_POST['contact']['shipto_name']
);

Then check for an error that may have been logged.

Having split the line into several can let PHP identify the line that has the actual problem.

Posted (edited)

Dirty Butter and Brian I have done what you both suggested.  No difference and nothing in my error log. Everything green and my fields show.

What about this.   email_content => "%s <%s> wrote to %s: --------------- %s ----------"

Thanks, Claudia

Are there more files or lines of code I need to edit or something?

Edited by Claudia M
Posted

This statement and the others like it may not be necessary:

$mailer->Shiptoname = strip_tags($_POST['contact']['shipto_name']);

You are attempting to assign values to keys in the Mailer (technically, the Mailer's "class properties"). The Mailer class may not be set up to handle this. And I doubt the Mailer class cares about anything not directly related to sending an email (From, To, Subject, and Body).

In the file cubecart.class.php:

Near line 1422 (for CC618), find:

$mailer->Body = sprintf($GLOBALS['language']->contact['email_content'], $_POST['contact']['name'], $_POST['contact']['email'], $department, html_entity_decode(strip_tags($_POST['contact']['enquiry']),ENT_QUOTES));

Broken into its parts:

$mailer->Body = sprintf(
$GLOBALS['language']->contact['email_content'], 
$_POST['contact']['name'], 
$_POST['contact']['email'], 
$department, 
html_entity_decode(strip_tags($_POST['contact']['enquiry']),ENT_QUOTES)
);

The first item in the list is the 'mask', followed by values to fill 'slots'.

The language file has this for the 'contact' group, 'email_content' string:

%s <%s> wrote to %s:
        ---------------
        %s
        ---------------

        This email is sent from the stores master email address but it is possible to reply directly to the sender using the reply button on your email software.

Note how the %s slots line up with the values in the list to fill those slots.

In the Contact Us case, to add your custom form elements to the email sent to you, you will need to add more %s slots, and then add the form elements to fill those slots.

Let's try this:

$mailer->Body = sprintf(
$GLOBALS['language']->contact['email_content']
,$_POST['contact']['name']
,$_POST['contact']['email']
,$department
,html_entity_decode(strip_tags($_POST['contact']['enquiry']),ENT_QUOTES)
,strip_tags($_POST['contact']['shipto_name'])
,$_POST['contact']['shipto_address1']
,$_POST['contact']['shipto_address2']
,$_POST['contact']['shipto_town']
,$_POST['contact']['shipto_state']
,$_POST['contact']['shipto_country']
,$_POST['contact']['shipto_postalcode']
,$_POST['contact']['shipto_other']
);

The first item in the list is the 'mask', followed by eight new values to fill eight new 'slots'.

The mask (language file 'contact' group, 'email_content' string) will have these eight new slots:

%s <%s> wrote to %s:
        ---------------
        %s
        Please ship to:
        %s
        %s
        %s
        %s
        %s
        %s
        %s
        %s
        ---------------

        This email is sent from the stores master email address but it is possible to reply directly to the sender using the reply button on your email software.

(There used to be an issue with angles in the language editor - the angles and internal contents were seen as tags and were stripped out when submitting changes. I think that has been sorted. But watch for misalignment between slot contents and slot positions.)

Posted (edited)

I did everything you said, Brian, and it is still not working.  This is the return email I got:

Claudia <xxxxxx@xxxx.net> wrote to :

        ---------------

        dsg

        ---------------

 

        This email is sent from the stores master email address but it is possible to reply directly to the sender using the reply button on your email software.

 

I added the {DEBUG} at the end of the contact file and everything was okay.  All fields showed up.

this is a sample of my skins/content.contact  NOTE I did change the fields to one word, which I also did went I tried your fix.

<div class="row">
        <div class="small-12 columns">
      <div class="row">
<div class="large-3 columns"><label for="contact_shipfullname" class="bold right inline show-for-medium-up">{$LANG.contact.shipfullname}</label></div>
<div class="small-12 large-8 left columns">
<input type="text" name="contact[shipfullname]" id="contact_shipfullname" value="{$MESSAGE.shipfullname}" placeholder="{$LANG.contact.shipfullname}"></div>
            </div></div>
  </div>

 

Edited by Claudia M
Posted

The 'Please ship to:' hard phrase isn't in the email, so I think the edited mask didn't take.

You can try to edit the definitions.xml file in /languages/, or make sure you chose the correct language to make changes to in admin.

Either way, see if clearing CubeCart's cache (admin, Maintenance, Rebuild tab, Clear Cache) will have CubeCart reload the language file.

Posted

I took out the "please ship to" and added the slots in admin. I had previously made the changes thru cPanel.  I had already moved my language to the definitions file ( from the en_US).  Cleared the cache many times and guess what!!  I works!!

Yeah once again to Brian!!!!!  Do you think it would be okay to move the language back to en_US?

Thank you!!!!

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...