Jump to content

Would like to add phone number field to contact us form


browneyedgirl

Recommended Posts

Hello, I am new to cubecart.  I am trying to modify the Contact us form to request the user to include a phone number and concatenate that information with the email "enquiry" section (i.e. email message body).  I'm looking for someone to help me understand, step by step,  how I can most easily do this.

I am using the "Foundation" skin/template and have been trying to play around with the content.contact.php file - I have managed to get it to display a field for entering the phone number, but I don't know how to get the information to be added to the email body.

 

Link to comment
Share on other sites

Welcome browneyedgirl! Glad to see you made it the forums.

Most web forms being submitted by the store visitor and page requests is handled by the CubeCart class (/classes/cubecart.class.php). In this case, the function named _contact() (near line 1324) is where you want to look.

This function does two things: processes the form submission, and gathers all that is necessary to create the form on the page.

In processing the form submission, the function starts with if (isset($_POST['contact'])) {. If the edited template form now has a form element that collects contact[phone], it will be in $_POST['contact']['phone'].

Eventually, we get to:

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

The last value to be placed:

strip_tags($_POST['contact']['enquiry'])

is where you want to append $_POST['contact']['phone'].

However, I suggest a better approach and that is to change the sprintf() mask to hold the distinct value of the phone number.

Unfortunately, the Language Editor may or may not be fixed in CC606 to allow for multi-line entries. The "real" phrase being used for the mask is:

%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 the line breaks. Editing this phrase in the Language Editor may not preserve the line breaks. There is also the issue (may have been fixed) of <%s> looking like an HTML 'tag' which gets stripped. I have recommended in the past to use (%s). We can try to use \n for line breaks, but that may get stripped, too.

So, we can make the edit to the CubeCart class function _contact() as follows:

(line wrapped for clarity)
$mailer->Body = 
  sprintf($GLOBALS['language']->contact['email_content'],
  $_POST['contact']['name'],
  $_POST['contact']['email'],
  $_POST['contact']['phone'],
  $department,
  strip_tags($_POST['contact']['enquiry']));

And, in the Language Editor, click the Edit icon of the language you are using, from the drop-down selector choose Contact, then change the 'email_content' phrase to:

%s (%s) and can be reached at %s, wrote to %s:\n        ---------------\n        %s\n        ---------------\n\n                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.

 

Link to comment
Share on other sites

bsmither,  thank you so very much for taking the time to provide such a detailed and well laid out  response.  I have made the changes, but there seems to be a problem with the server at the moment and I can't  save/test the changes.  I will try again tomorrow.   Your help is very much appreciated!

Link to comment
Share on other sites

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