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