Zen Cart Logo
Forums / Basic Configuration / Customer Specified Subject Line for Contact Form

Customer Specified Subject Line for Contact Form

Locked

Views: 11,681

Results 1 to 19 of 19
This thread is locked. New replies are disabled.
27 Jul 2006, 8:31 PM
#1
jacdesigner avatar

jacdesigner

Zen Follower

Join Date:
Jun 2005
Location:
Austin, Texas, US
Posts:
205
Plugin Contributions:
0

Customer Specified Subject Line for Contact Form

Currently the Contact Us form is referring to a pre-set default text for the subject line of the emails that come in. This is not helpful for my client, since he gets a ton of these emails and wants a good way to prioritize his customer's inquiries.

Is it possible to add an additional field for subject line in the contact page template and then edit contact_us.php to call the variable for that new field rather than using the static text like "message from store name"?

It seems like it would be, but as I am a somewhat novice programmer (I've been using Zencart for a while now, but I still am no php expert)....I am wondering just how complex it might get.

I have done lots of searching in the forum and saw the posts about adding some additional input fields for just collecting more info....but this seems slightly different.

Is trying to mess with this particular field (email_subject) not a good idea?

Please advise! Thank you!

29 Jul 2006, 6:05 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Customer Specified Subject Line for Contact Form

Certainly do-able. I've got a similar task on a project list for a client. It's not at the top of the list, but will be done at some point...

31 Jul 2006, 7:26 PM
#3
jacdesigner avatar

jacdesigner

Zen Follower

Join Date:
Jun 2005
Location:
Austin, Texas, US
Posts:
205
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Holy cow I am so proud of myself I could just spit (jk). I am just a very novice person when it comes to php but I figured out how to do this. Here is how I accomplished this on my test zencart store:

First I opened the file in my /includes/languages/english/custom template folder/
called: contact_us.php

I entered in the following line in between my other input fields so I could prepare to add a new text field in my template:
**
define('ENTRY_DESCRIPTION', 'Description for Subject:');
**

Next, I edited the file called tpl_contact_us_default.php in:
templates/my template name/templates/

I added another couple rows with the following code to make way for my custom subject line which I call "description":

**

<tr> <td class="plainBoxHeading" colspan="2"><?php echo ENTRY_DESCRIPTION; ?></td> </tr> <tr> <td class="main" colspan="2"><?php echo zen_draw_input_field('description', ($error ? $_POST['name'] : $description), ' size="50"'); ?></td> </tr> <tr> ** And lastly, I edited the EMAIL_SUBJECT properties in the contact_us.php file to the following: ** define('EMAIL_SUBJECT', 'Question ' . $description);**

I received the email with my appended description in the subject line. Woo hoo!

3 Aug 2006, 6:08 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Customer Specified Subject Line for Contact Form

That's a great start, and will probably suffice for your needs.

A couple things I note though:
You may have some problems with that if the person filling in the form makes an error and the validation script shows error messages.
You may also be vulnerable to SQL injection risks if you don't also sanitize the $_POST['description'] data prior to using it. You didn't show how you're using it, so it's hard to tell how much of a risk you have.

21 Feb 2007, 11:49 PM
#5
michellyaqua12 avatar

michellyaqua12

New Zenner

Join Date:
Jan 2007
Location:
Boston, MA, USA
Posts:
40
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hmm. I have a subject field added from this download, but when I try changing the code in contact_us.php to this:

define('EMAIL_SUBJECT', 'Message about '. $subject);

...it doesn't work. Anyone have any ideas why not?

It is defined as $subject in tpl_contact_us_default.php:

<?php echo zen_draw_input_field('subject', $subject, ' size="40" id="subject"')
8 Mar 2007, 5:40 AM
#6
fizfaz avatar

fizfaz

New Zenner

Join Date:
Dec 2006
Posts:
14
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

MichellyAqua12:

Hmm. I have a subject field added from this download, but when I try changing the code in contact_us.php to this:

define('EMAIL_SUBJECT', 'Message about '. $subject);

...it doesn't work. Anyone have any ideas why not?

It is defined as $subject in tpl_contact_us_default.php:

<?php echo zen_draw_input_field('subject', $subject, ' size="40" id="subject"')

I also want to add email subject using that contribution.. and try to test myself.. I find that there are no email subject at the customer email that I received...even though I filled in the subject at contact us form when I test run, Can somebody help..

8 Mar 2007, 5:56 AM
#7
michellyaqua12 avatar

michellyaqua12

New Zenner

Join Date:
Jan 2007
Location:
Boston, MA, USA
Posts:
40
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

If you edit includes/modules/pages/contact_us/header_php.php, you can at least get the subject to be listed in the email you receive. I'd still like the subject to appear in the email subject line, because it's easier to sort through emails that way, but whatever, at least I can see what the subject is now.

Ok, first go to admin/includes/languages/english/email_extras.php and find this (should be right near the top):

define('OFFICE_EMAIL','E-mail:');

Add this below it:

define('OFFICE_SUBJECT','Subject:');

Then go to includes/modules/pages/contact_us/header_php.php. Go to line 50 or so and find this:

// Prepare Text-only portion of message
    $text_message = OFFICE_FROM . "\t" . $name . "\n" .
    OFFICE_EMAIL . "\t" . $email_address . "\n\n" .

Replace with this:

// Prepare Text-only portion of message
    $text_message = OFFICE_FROM . "\t" . $name . "\n" .
    OFFICE_EMAIL . "\t" . $email_address . "\n" .
    OFFICE_SUBJECT . "\t" . $subject . "\n\n" .

You're really just changing part of the OFFICE_EMAIL line, and adding a line below it for the subject. (I didn't edit the HTML message options because I receive text-only emails).

That should get the emails you receive to now list the subject within the body of the email!

8 Mar 2007, 9:16 AM
#8
fizfaz avatar

fizfaz

New Zenner

Join Date:
Dec 2006
Posts:
14
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

MichellyAqua12:

If you edit includes/modules/pages/contact_us/header_php.php, you can at least get the subject to be listed in the email you receive. I'd still like the subject to appear in the email subject line, because it's easier to sort through emails that way, but whatever, at least I can see what the subject is now.

Ok, first go to admin/includes/languages/english/email_extras.php and find this (should be right near the top):

define('OFFICE_EMAIL','E-mail:');

>  
> ```
define('OFFICE_SUBJECT','Subject:');
```Then go to includes/modules/pages/contact_us/header_php.php. Go to line 50 or so and find this:
>  
> ```
// Prepare Text-only portion of message
    $text_message = OFFICE_FROM . "\t" . $name . "\n" .
    OFFICE_EMAIL . "\t" . $email_address . "\n\n" .
```Replace with this:
>  
> ```
// Prepare Text-only portion of message
    $text_message = OFFICE_FROM . "\t" . $name . "\n" .
    OFFICE_EMAIL . "\t" . $email_address . "\n" .
    OFFICE_SUBJECT . "\t" . $subject . "\n\n" .
```You're really just changing part of the OFFICE_EMAIL line, and adding a line below it for the subject. (I didn't edit the HTML message options because I receive text-only emails).
>  
> That should get the emails you receive to now list the subject within the body of the email!

Oh ... actually thats because of my mistake when upload the header_php.php file.. upload in wrong directory.. its OK right now.. I got the subject in the email.. instead of default subject from store name...

Btw, thanks for help.. and I also want to try as your suggestion to see the different.. Thanks
8 Mar 2007, 6:05 PM
#9
michellyaqua12 avatar

michellyaqua12

New Zenner

Join Date:
Jan 2007
Location:
Boston, MA, USA
Posts:
40
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

The code I gave you is so you can see what subject the customer put - it'll appear in the body of the email. For me, with the text emails I receive, it looks like this:

From: ____
Email: ___
Subject: ___


(message body here)

etc.

I thought you were having the same problem as me where you installed the subject add-on but then had no way of knowing what the subject was because it didn't show up anywhere.

Were you able to get the subject that the customer writes to appear in the subject line of the email you receive? In place of "Message from STORE_NAME"? That's what I was trying to do, but it won't work for me.

9 Mar 2007, 1:00 AM
#10
fizfaz avatar

fizfaz

New Zenner

Join Date:
Dec 2006
Posts:
14
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Yes I got the subject line that been filled in by the customer replace the " Message from store name"
i.e;
**Subject: ** testing123
**From: ** "tester" [email protected]
**Date: ** Thu, March 8, 2007 6:31 pm
**To: ** [email protected]
**Priority: ** Normal

From: tester
Email: test@yahoo.com


This my testing only..


Office Use Only:
Etc..

Just upload all the mod files to the respective directory... The first my problem is my mistake uploading the header_php.php file... you can try to start over again by overwrite the respective files by that mod..

29 Oct 2007, 12:12 PM
#11
kallep avatar

kallep

New Zenner

Join Date:
Oct 2007
Location:
Johannesburg, South Africa
Posts:
8
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hi All,

Yay ZenCart. I have finished my first installation and had fun and got it going with minimal fuss and no questions until now (the info on the web is helpful but scattered) even though my PHP knowledge is still limited. I have just added the Contact Us-Subject line MOD and it worked out the box.

I would like to add a small amount of functionality to this MOD.

In the past I have made use of mailto:address@domain?subject=PageTopic but wish to remove the harvestable email links and send visitors to the Contact Us form instead. However I want to populate the subject field with manual text from the link as below.

http://dogtags.co.za/index.php?main_page=contact_us&default_subject=Website%20privacy%20query

Alternately I could in this instance use an automatic indication of the referring page in the Subject as is or with some lookup as the number of links is limited to one per page and on the same site.

http://dogtags.co.za/index.php?main_page=contact_us&referrer=privacy

I can envisage that it would probably only require a small addition to one or two files to load the PHP GET variable, sanitize it for security, and then insert it into the <b>value</b> field on the INPUT FORM.

One could use this same variable then to insert the default Message from SHOP_NAME from the admin interface.

What will take me hours and might be risky is likely just a moments reflection for the gurus out there. Is the MOD developer still active, it is probably the best place to make the change.

Regards

Kalle

Zen Cart Fan

29 Oct 2007, 3:50 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Customer Specified Subject Line for Contact Form

$current_page_base is the variable that contains whatever "main_page=" is set to, and is already sanitized.

Thus, you could manually extend every instance of your contact-us link using something like this:
Change zen_href_link(FILENAME_CONTACT_US)to this:```
zen_href_link(FILENAME_CONTACT_US[B], 'referrer=' . $current_page_base[/B])

30 Oct 2007, 11:07 AM
#13
kallep avatar

kallep

New Zenner

Join Date:
Oct 2007
Location:
Johannesburg, South Africa
Posts:
8
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hi DrByte,

Thanks. I changed it first in modules/sideboxes/CUSTOM/information.php to

zen_href_link(FILENAME_CONTACT_US, 'referrer=While_visiting_page:' . $current_page_base)

I will change the other relevant occurrences when this one works (which is a universal one)

And it gets the data to the GET request perfectly from the information menu which is more than I hoped for.

I then changed the following in templates/CUSTOM/templates/tpl_contact_us_default.php which is the file with the Subject MOD

zen_draw_input_field('subject', $referrer, ' size="40" id="subject"', 'text', false)

This should take the $referrer variable and put into the value field (even if the GLOBAL subject were to exist because of the false) and it works as expected with static data and testing using the $name variable. However the $referrer variable is empty even though it shows up correctly in the GET request as visible in the title bar.

Some other layer of stuff is stripping out the variable before it gets to the form, very intricate this.

Another hint would be welcome.

Regards

Kalle

Zen Cart investigator

30 Oct 2007, 3:21 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Customer Specified Subject Line for Contact Form

What is $referrer supposed to contain? Where do you set that?

30 Oct 2007, 4:04 PM
#15
kallep avatar

kallep

New Zenner

Join Date:
Oct 2007
Location:
Johannesburg, South Africa
Posts:
8
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hi,

I am hoping to get the value from the URL that calls the Contact Us page.

If someone clicks the **Contact Us **link in the Information box while on my Privacy Policy page the URL is as follows

http://dogtags.co.za/index.php?main_page=contact_us&referrer=While_visiting_page:privacy

with privacy inserted automatically as per your earlier suggestion using the zen_href_link change.

I want the Subject field on the Contact Us page be populated with the value of on my While_visiting_page:privacy when it is reached from the Privacy policy page.

The $name variable populates the Name field with the users name if he is logged in, the $email does the same. I want the calling URL to pass the referrer variable to the value option of the subject field in the input form.

Regards

Kalle

Zen Cart researcher

30 Oct 2007, 4:23 PM
#16
kallep avatar

kallep

New Zenner

Join Date:
Oct 2007
Location:
Johannesburg, South Africa
Posts:
8
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hi,

The link got a bit messed up. I notice smileys attacked my example as well :-)

ht tp://dogtags.co.za/index.php? main_page=contact_us&referrer=While_visiting_page:privacy

I am missing something about PHP functionality here. I was under the impression that parameters sent in the GET URL were parsed as simple PHP variables. I think this is the case but some layer of Zen Cart parsing is stripping out extra variables that it does not understand.
If the user is not logged in the session is tracked with zenid="long hash code" in the URL and this shows up on all the links. Obviously something can parse multiple parameters in the input variables but I don't know enough about where to look. The intemediate layer needs to pass any extra parameters forward or not clear parsed variables or something. I'll get there eventually, it is probably a security measure to prevent malicious parameters from leaking through.

I just had a thought, PHP has access to a system variable of some sort that has the full referring page URL, for this application I might be able to parse out the mainpage=value and use it directly on the contact-us page, I'll try that if I cannot get the more flexible variable passing arrangement to work.

Thanks for taking the time, lovely service you guys and gals offer.

Regards

Kalle
P.S. Takes me more than 7 minutes to edit a posting so here I am posting again

30 Oct 2007, 4:23 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Customer Specified Subject Line for Contact Form

Then use $current_page_base again

31 Oct 2007, 4:14 AM
#18
kallep avatar

kallep

New Zenner

Join Date:
Oct 2007
Location:
Johannesburg, South Africa
Posts:
8
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hi All,

Long night <big grin>. I got everything to work as I wanted and the functionality of PHP that I predicted was there all along, just got to read up on PHP.net.

In the file includes/templates/CUSTOM/templates/tpl_contact_us_default.php I altered the code that is used for the subject field as shown below.

This is the **Contact_us:Subject MOD **file that I further modded.

I took out the earlier changes to the information.php file as it is no longer required for this to work and the single change below is all that is required.

What it does is the following. If you type in your page link by hand

http://dogtags.co.za/index.php?main_page=contact_us

if places the old default subject 'Message from ' . STORE_NAME into the Subject field of your email as before (or if you have reached the site from outside and click Contact Us menu from the landed page, it will not have the ?main_page=index set yet).

If you use any link to go to the contact us page it will look for the main_page= variable in the HTTP_REFERER system variable and add it to the interesting subject line 'While visiting page: ' . $main_page (it will ignore $zenid if present) links from outside that do not have the main_page= will be treated as unreferrerd (links in from another Zen Cart site would probably be correctly Subjected).

If you craft a manual link to the Contact Us page as follows

http://dogtags.co.za/index.php?main_page=contact_us&default_subject=Website%20ZEN%20cart%20query"

It will use the $_GET variable $default_subject (and it converts the %20 characaters by some magic) and place it verbatin into the Subject field.

Feel free to test it on my site the links in the body text usually send the default_subject text so you can see how it works. It is a live site so be gentle, emails on my contact form are ok, I may reply if you write something intertesting.

<?php $cu_default_subject = $_GET['default_subject'];
if ($cu_default_subject == '') { 
    $cu_referrer = $_SERVER['HTTP_REFERER'];   
    $cu_first = strpos($cu_referrer, 'main_page=');
    if ($cu_first === false) {
        $cu_default_subject = 'Message from ' . STORE_NAME; 
    } else {
        $cu_first = $cu_first + 10;
        $cu_last = strpos($cu_referrer, 'zenid=');
        if ($cu_last === false) {
            $cu_last = strlen($cu_referrer) + 1; 
        };
        $cu_default_subject = 'While visiting page: ' . substr ($cu_referrer, $cu_first , $cu_last-$cu_first - 1); 
    };
};
echo zen_draw_input_field('subject', $cu_default_subject, ' size="40" id="subject"', 'text', false) . '<span   class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

Thanks for listening. I cannot support this MODmod yet as I was guessing a lot when I made it and not sure of the security issues though there seems to be little chance of great disaster. I need to sanitise the $default_subject variable somehow, I saw a function to do this but cannot remember what it was.

Feel free to use the contact page in the examples to send me a note if you try it and get it to work, I think it might be an idea to incorporate it in full or part into the lovely Subject Field MOD if the MODer is still active.

I have no idea how it will react to the Combo Box feature of the Subject MOD that was proposed but it might be able to use the Combo table to translate the $main_page variable to pretty text somehow perhaps.

DrByte, thanks for the guidance, this stuff was so easy in principle I just did not know how to ask the right questions, I just knew it could be done. Very happy camper now. The power of Zen Cart is truly amazing.

Regards

Kalle

Zen Cart manipulator

31 Oct 2007, 10:01 AM
#19
kallep avatar

kallep

New Zenner

Join Date:
Oct 2007
Location:
Johannesburg, South Africa
Posts:
8
Plugin Contributions:
0

Re: Customer Specified Subject Line for Contact Form

Hi All,

I found a bug and decided to fix it with a bit of PHP parsing functions. I had to do it in stages but the result is what I wanted in the first place. It gets the $_GET variable $default_subject or the HTTP_REFERER variable main_page and puts it in the INPUT form subject field value parameter.

Replace the code in the Contact_Us___add_subject_field MOD file
tpl_contact_us_default.php

<?php echo zen_draw_input_field('subject', $subject, ' size="40" id="subject"') . '<span class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

With the code

<?php $cu_default_subject = $_GET['default_subject'];
if ($cu_default_subject == '') { 
    parse_str(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY));
    if ($main_page =='') {
        $cu_default_subject = 'Message from ' . STORE_NAME; 
    } else {
        $cu_default_subject = 'While visiting page: ' . $main_page; 
    };
};
echo zen_draw_input_field('subject', zen_db_prepare_input($cu_default_subject), ' size="40" id="subject"', 'text', false) . '<span   class="alert">' . ENTRY_REQUIRED_SYMBOL . '</span>'; ?>

I think that about covers it for the Subject field Auto-complete MODmod. I found a sanitise function but have no idea if it is suitable. I welcome any input on that. Sorry it took so many posts but at least the new folk can see that it is a struggle for everyone in the beginning.

Regards

Kalle

PHP maniac