Contact forms to custom recipient email address
PermalinkI 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
Just have not been successful in hardcoding the form or pulling the attribute. An example would be wonderful. I am kind of stuck.
$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...
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.
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.
Any guidance would be much appreciated.
Thank you!
public function sendNotifications() { ///CUSTOM RECIPIENT EMAIL ADDRESS $page = Page::getCurrentPage(); $pageEmail = $page->getAttribute('property_contact_email'); if(strlen(trim($pageEmail)){ $this->answerSet->sendNotification($pageEmail); } //Send main notification email if((($this->f->properties['mailTo'] != '') && ($this->f->properties['sendMail'] == '1')) || (($this->f->properties['mailTo'] != '') && ($this->f->properties['sendMail'] == '2') && ($this->mode == 'add'))) { $toAddresses = explode(',',$this->f->properties['mailTo']); foreach($toAddresses as $toAddress) { $toAddress = trim($toAddress); $adminUserInfo=UserInfo::getByID(USER_SUPER_ID); $this->answerSet->sendNotification($toAddress); }
Link:http://aptlivingguide.com/index.php?cID=6973...
It seems there is a missing ")" in the code example you posted but it still fails after adding that with this message...
Fatal error: Call to a member function getAttribute() on a non-object in /home/aptlg/public_html/packages/sixeightforms/helpers/form/processor.php on line 320
Fatal error: Call to a member function getAttribute() on a non-object in /home/aptlg/public_html/packages/sixeightforms/helpers/form/processor.php on line 320
<input name="cID" type="hidden" value="<?php echo Page::getCurrentPage()->getCollectionID(); ?>" />
then change the code in the helpers/form/processor.php to
Will have to verify that the site is sending emails at all.
On Apr 5, 2017 10:41 AM, "concrete5 Community" <discussions@concretecms.com>
wrote:
Thanks again for the help with the recipient email address from page attribute. I am trying to pass in another page attribute....
<input name="property_name" type="hidden" readonly="true" value="<?php echo Page::getCurrentPage()->getAttribute('property_name'); ?>" />
I added a hidden input to my form with the same handle and told it to send all html fields. It worked once, then stopped. Any help here?
I should mention I did this in public_html/packages/sixeightforms/blocks/sixeightforms/view.php
Thanks in advance!
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?