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