Send Contact Form to Selected Recipient

Author Message

Nathan Kelly

Wednesday 19 October 2005 1:22:25 am

Hi, I'm making a contact form for a company who has two divisions, lets just call them division1 and division2 for now.

On the form I have a selection datatype and two options, one for each division, I need to use radio buttons here.

I have created two recipients with the email datatype:-

division1[AT]company.com
division2[AT]company.com

So if you select division1 the email is sent to division1[AT]company.com.

I am adapting the form from the companies current website and they need this functionality in the new EZ powered site. The old site used a CGI script to do this.

My question is can eZp handle this or is this another case for an extension?

I figured it would be possible without having to touch PHP but I'm not sure how I would do it.

Any suggestions/advice appreciated.

Cheers!

Pardon me while I burst into flames...

Nathan Kelly

Thursday 20 October 2005 2:09:50 am

Hi, after spending all day at this I still haven't got very far.

I have made an override for content/collectedinfomail/form.tpl and I'm trying to pass the variable from my (recipient selection) to the recipient in the for mentioned template (below):

{set-block scope=root variable=email_receiver}
    {$object.data_map.reciver.content}
{/set-block}

I figure I need some kind of 'if else' structure here but I also don't know how to get the value from my select box, by the way I'm using the enhanced selection from the contribs which seems to create an attribute id.

I really need some advice from someone with more experience who may have dealt with this type of thing. It seems so possible but my limited knowledge of ezpublish is really making it hard.

Also I noticed that when I can't get my template to work the email is sent to the admin email address, I don't have a recipient set in the site.ini because I thought that would make it even harder to get working, but maybe it would make it easier?

I have looked at other forum threads that have similar situations and as far as I can tell they have used separate forms to get what they need, but I need to be able to select the recipient at runtime, so they weren't much help.

Please help, I'm going grey...!

Cheers!

Pardon me while I burst into flames...

Nathan Kelly

Thursday 20 October 2005 10:18:44 pm

Ok I finally got this to work, and it works surprisingly well.

Just in case others need similar functionality I'll try to explain how I did it.

First I created a form with all of the required fields:

name:
phone no:
email:

etc.

I added a selection attribute using the enhanced selection extension datatype from the contribs
http://ez.no/community/contribs/datatypes/enhanced_selection

I have 2 divisions so I put 2 options in the select box:

option1: division1
option2: division2

Lastly I added 2 recipient email addresses using the email datatype:

Recipient Division1: div1[at]company.com
Recipient Division2: div2[at]company.com

I override the template file content/collectedinfomail/form.tpl following instructions found at: http://ez.no/products/ez_publish_cms/documentation/customization/components/information_collection

In my override template I replace this:

{set-block scope=root variable=email_receiver}
    {$object.data_map.receiver.content}
{/set-block}

With this:

{section loop=$collection.attributes}

    {if $:item.data_text|eq(Division1)}
    
        {set-block scope=root variable=email_receiver}
            {$object.data_map.recipient_division1.content}
        {/set-block}
	
    {elseif $:item.data_text|eq(Division2)}
    
        {set-block scope=root variable=email_receiver}
	    {$object.data_map.recipient_division2.content}
	{/set-block}
	
    {else}
    
	{* fallback to site.ini.append.php (EmailReceiver) *}
	
    {/if}
    
{/section}

If you select Division1 your email message is sent to div1[at]company.com and vice-versa.

The $:item.data_text is just the value of the select options, I used the |eq() operator to find the option, this seems to work perfectly but I'm not sure if there is a better way to do it.

If you know of a better way please let me know.

I hope this helps others.

Cheers!

Pardon me while I burst into flames...

Nathan Kelly

Thursday 20 October 2005 11:52:58 pm

AAHhh, I thought I had this working but now for some unknown reason my override is failing, this is out of the blue as it was working then it just stopped?

Taking into account I made no changes to any files at all does anyone have any suggestions why an override would just stop working?

[EDIT] Ok my overrides have started to work again, I don't know why?

Now the problem I'm having is the code in the above post has stopped working, once again for seemingly no reason. It work about 10 - 15 times, I changed the email setting to include ContentType=text/html in settings/override/site.ini.append.php and that seems to be when the wheels fell off. I have since changed it back to text/plain but my code that worked perfectly is now not working?

I ran a table check on my database in phpmyadmin for fear there may be a corrupt table or row and most of the tables checked out ok all but this message:


Problems with indexes of table `ezcontentobject_attribute`
Warning More than one INDEX key was created for column `contentobject_id`
Problems with indexes of table `ezenumobjectvalue`
Warning PRIMARY and INDEX keys should not both be set for column `contentobject_attribute_id`

Could anyone tell me if this might be a problem, and/or how to fix it anyway?

Cheers!

Pardon me while I burst into flames...

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 20 2025 17:34:19
Script start
Timing: Jan 20 2025 17:34:19
Module start 'layout'
Timing: Jan 20 2025 17:34:19
Module start 'content'
Timing: Jan 20 2025 17:34:20
Module end 'content'
Timing: Jan 20 2025 17:34:20
Script end

Main resources:

Total runtime0.9230 sec
Peak memory usage4,096.0000 KB
Database Queries58

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 588.0391151.2266
Module start 'layout' 0.00790.0095 739.265636.6797
Module start 'content' 0.01750.9042 775.9453559.5000
Module end 'content' 0.92170.0013 1,335.445315.8281
Script end 0.9230  1,351.2734 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3521160.0002
Check MTime0.00130.1434160.0001
Mysql Total
Database connection0.00180.197110.0018
Mysqli_queries0.853592.4625580.0147
Looping result0.00070.0764560.0000
Template Total0.876094.920.4380
Template load0.00240.262820.0012
Template processing0.873594.636920.4368
Template load and register function0.00010.009210.0001
states
state_id_array0.00080.084510.0008
state_identifier_array0.00100.113520.0005
Override
Cache load0.00200.2176630.0000
Sytem overhead
Fetch class attribute can translate value0.00050.051910.0005
Fetch class attribute name0.00090.095350.0002
XML
Image XML parsing0.00060.066210.0006
class_abstraction
Instantiating content class attribute0.00000.002480.0000
General
dbfile0.00110.1213160.0001
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs