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
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
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.
Just have not been successful in hardcoding the form or pulling the attribute. An example would be wonderful. I am kind of stuck.
hello - you could override your form block controller and add something like the following:
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...
$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);
Viewing 15 lines of 19 lines. View entire code block.
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...
Thanks for diggin into this! I do need more detail though if possible. Am I just putting this in my page template?
hello - I'd somehow assumed you are using Concrete 5.7 - is that correct or are you using 5.6?
I am using 5.6.2.1 as I am not familiar with the new 5.7
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.
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.
Hi Andy, did you have a chance to look at this anymore?
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.
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.
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);
Viewing 15 lines of 21 lines. View entire code block.
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.
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!
Any guidance would be much appreciated.
Thank you!
Thank you for this modification !
Were you able to make this modification work?
Did anyone actually get this to work? A step by step walk-through would be sweet!! I am using Advanced Forms on 5.6 and need to use an email_address custom page attribute as the recipient.
Thanks for that. Here is what I have but it is failing... this is in the processor for sixeightforms
Link:http://aptlivingguide.com/index.php?cID=6973...
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); }
Viewing 15 lines of 52 lines. View entire code block.
Link:http://aptlivingguide.com/index.php?cID=6973...
Can you provide more information about what is "failing"?
Parse error: syntax error, unexpected '{' in /home/aptlg/public_html/packages/sixeightforms/helpers/form/processor.php on line 333
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
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
if(strlen(trim($pageEmail)){ needs to be if(strlen(trim($pageEmail))){
Yes, that is what I changed it to but now receive this error..
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
Sorry, I guess this is called from a tools file so it won't have access to the current page, this would take quite a bit of customizing. If you would like you can contact me via PM and I could give you a quote to do it.
Bummer, ok. Unfortunately I can't afford that cost right now.
One thing you could try would be to add the cID into the form by adding this line into the blocks/sixeightforms/view.php
then change the code in the helpers/form/processor.php to
<input name="cID" type="hidden" value="<?php echo Page::getCurrentPage()->getCollectionID(); ?>" />
then change the code in the helpers/form/processor.php to
Thanks for that. It's not error in out now, but didn't receive an email.
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:
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:
IT'S WORKING!! Thank you so much!! My issue was that we were trying to use SMTP method. When I switched to the default PHP method, it worked!
I assume it would be just as simple to pass another pageAttribute to the email that is sent? Like the property_name which is a pageAttribute?
I can get a page attribute to show in a hidden input in the form. Just not sure how to pass that to the email. Ideas?
Hi Hutman,
Thanks again for the help with the recipient email address from page attribute. I am trying to pass in another page attribute....
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!
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?