Contact forms to custom recipient email address

Permalink
Hey everyone!

I have been searching and searching but have not been able to track down a viable answer.

I have a site that shows apartments available in many different areas. Each property has a different user that manages their content. So each user is assigned as the owner of that particular property. They manage all of this via Dashboard Page Manager/Composer. There is an Owner Contact Email Address attribute that they enter their email address in.

What i need is to have a contact form on the property page that a visitor can fill out and have it send to the Owner Contact Email Address attribute and the Super Admin.

I am fine hardcoding this into the page_type template as i am sure that's what I will have to do. I have seen ways of using a dropdown to select recipient, but that won't work. It HAS TO use the custom attribute defined.

Any help out there!? I should mention I am using 5.6.2.1

View Replies:
AndyJ replied on at Permalink Reply
Hi,
you have a separate page for each property?
Each page has this attribute embedded in it for the owners email address?

You are using the standard form block?

If all of the above are true you could override the form block or use a custom template, grab the attribute value from the page and add it to your outgoing emails.

Does that sound about right?
aaronmarp replied on at Permalink Reply
Yes..all of the above is true since it's a page being created by Dashboard Page Manager.

Just have not been successful in hardcoding the form or pulling the attribute. An example would be wonderful. I am kind of stuck.
AndyJ replied on at Permalink Reply
hello - you could override your form block controller and add something like the following:

$ownerEmail = Page::getCurrentPage()->getAttribute('my_attribute_handle');
if($ownerEmail)   {
   if( Config::get('concrete.email.form_block.address') && strstr(Config::get('concrete.email.form_block.address'),'@') ){
      $formFormEmailAddress = Config::get('concrete.email.form_block.address');
   }else{ 
      $adminUserInfo=UserInfo::getByID(USER_SUPER_ID);
      $formFormEmailAddress = $adminUserInfo->getUserEmail(); 
   }
   $mh = Loader::helper('mail');
   $mh->to( $ownerEmail ); 
   $mh->from( $formFormEmailAddress ); 
   $mh->replyto( $replyToEmailAddress ); 
   $mh->addParameter('formName', $this->surveyName);
   $mh->addParameter('questionSetId', $this->questionSetId);
   $mh->addParameter('questionAnswerPairs', $questionAnswerPairs);


add this directly above the following line:

if(intval($this->notifyMeOnSubmission)>0 && !$foundSpam){


caveats:

If you don't know what I mean by overriding the controller then please ask.

The above code is untested and has no guarantees but there should be enough there to push you in the right direction.

The above sample code only checks if the attribute is in the page and populated; depending on exactly how this should function you might also want to check the pagetype or template being used first. It will not work properly if the form is already set to send to another recipient, nor will it take into account any other forms you may have on the same page.

Someone brighter than me might come along and point out a far better way of doing this...
aaronmarp replied on at Permalink Reply
Thanks for diggin into this! I do need more detail though if possible. Am I just putting this in my page template?
AndyJ replied on at Permalink Reply
hello - I'd somehow assumed you are using Concrete 5.7 - is that correct or are you using 5.6?
aaronmarp replied on at Permalink Reply
I am using 5.6.2.1 as I am not familiar with the new 5.7
AndyJ replied on at Permalink Reply
hi, the code I posted is for 5.7 so it won't work. Don't try to use it.
The principles for 5.6 are the same - but the code is different. I'll post you some sample code a little later - unless someine else chimes in before I get back.
aaronmarp replied on at Permalink Reply
Hi Andy, did you have a chance to look at this anymore?
AndyJ replied on at Permalink Reply
hello,
got busy and sidetracked - the code for 5.6 is virtually the same - I'll post below. But, you don't embed it in the page - this is to add to an override of your form block controller.

$ownerEmail = Page::getCurrentPage()->getAttribute('my_attribute_handle');
         if($ownerEmail)   {
            if ($this->sendEmailFrom !== false) {
               $formFormEmailAddress = $this->sendEmailFrom;
            } else if( strlen(FORM_BLOCK_SENDER_EMAIL)>1 && strstr(FORM_BLOCK_SENDER_EMAIL,'@') ){
               $formFormEmailAddress = FORM_BLOCK_SENDER_EMAIL;
            }else{
               $adminUserInfo=UserInfo::getByID(USER_SUPER_ID);
               $formFormEmailAddress = $adminUserInfo->getUserEmail();
            }
            $mh = Loader::helper('mail');
            $mh->to( $ownerEmail );
            $mh->from( $formFormEmailAddress );
            $mh->replyto( $replyToEmailAddress );
            $mh->addParameter('formName', $this->surveyName);


Again the same caveats apply as before - this should point you in the right direction.

If you have questions please post them here. I would go through the documentation on overriding core files in the documentation to be fully informed.
aaronmarp replied on at Permalink Reply
Hey AndyJ, I forgot about this post till now. Could you give me a little more direction here? I tried to override the Form Block but am unable to get it to work.

Any guidance would be much appreciated.

Thank you!
timconsidine replied on at Permalink Reply
timconsidine
Thank you for this modification !
aaronmarp replied on at Permalink Reply
Were you able to make this modification work?