Forums / Developer / Send Contact Form to Selected Recipient

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

eZ debug

Timing: Jan 20 2025 15:14:14
Script start
Timing: Jan 20 2025 15:14:14
Module start 'content'
Timing: Jan 20 2025 15:14:15
Module end 'content'
Timing: Jan 20 2025 15:14:15
Script end

Main resources:

Total runtime1.3238 sec
Peak memory usage4,096.0000 KB
Database Queries195

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 587.8281180.8281
Module start 'content' 0.00581.2086 768.6563563.5547
Module end 'content' 1.21440.1094 1,332.2109340.7578
Script end 1.3238  1,672.9688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.2993210.0002
Check MTime0.00150.1133210.0001
Mysql Total
Database connection0.00070.051210.0007
Mysqli_queries1.229292.85311950.0063
Looping result0.00180.13411930.0000
Template Total1.294597.820.6473
Template load0.00180.136720.0009
Template processing1.292797.647820.6464
Template load and register function0.00020.011910.0002
states
state_id_array0.00090.069910.0009
state_identifier_array0.00090.070920.0005
Override
Cache load0.00170.1250630.0000
Sytem overhead
Fetch class attribute can translate value0.00130.099720.0007
Fetch class attribute name0.00090.069150.0002
XML
Image XML parsing0.00270.202720.0013
class_abstraction
Instantiating content class attribute0.00000.002180.0000
General
dbfile0.00570.4279270.0002
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs