brandy Posted September 19, 2023 Share Posted September 19, 2023 Hi! I am using Formbuilder on a website. The form is for contacting, if you are interested in a real estate. With the following code I read out, on which site you are sending the contact form: <?php $form = $forms->render('kontakt', [ 'form_page' => $page->parent->title . " " . $page->title ]); ?> So you receive a mail with the parent-page and page-title as subject, which works perfectly. Is it now possible to extend this and send the contact-form to different mailadresses, depending on the page-parent? I do have a field in the parent, which is linked to the right contact-information. Thanks a lot! Link to comment Share on other sites More sharing options...
elabx Posted September 19, 2023 Share Posted September 19, 2023 I think you'd have to customize the autoresponder template from FormBuilder. Check the instructions in site/modules/FormBuilder/email-autoresponder.php, in the comments at the top of the file. Link to comment Share on other sites More sharing options...
brandy Posted September 20, 2023 Author Share Posted September 20, 2023 Thanks a lot! But in the file there is no information about the sender. Where does the form get its sending information? Thanks a lot! Link to comment Share on other sites More sharing options...
elabx Posted September 20, 2023 Share Posted September 20, 2023 You know what, I misread your issue. What could probable work is placing a hook in emailFormReady https://processwire.com/store/form-builder/hooks/#where-to-place-hooks wire()->addHookBefore("FormBuilderProcessor::emailFormReady",function($e){ /** @var InputfieldForm **/ $form = $e->arguments(0); /** @var FormBuilderEmail **/ $email = $e->arguments(1); if($form->name !== "the_form_in_question") return; $page_id = $form->getChildByName('form_page_id'); if($page_id){ $contact_email = wire('pages')->get($page_id)->contact_email; $email->to = $contact_email; } }) form_page_id would be a hidden field in the form where you save the page_id, not sure if there is a nicer way to do this! That is, without this hidden field to pass on the id info. Link to comment Share on other sites More sharing options...
brandy Posted September 25, 2023 Author Share Posted September 25, 2023 Thanks a lot! I do have a construction, like this, for the emailSubject: <?php $processor = $event->object; $processor->emailSubject = "Page title is: $page->title"; echo $form; ?> Is it possible to make it very simple like $processor->emailReceipient = Only a quick thought! 1 Link to comment Share on other sites More sharing options...
elabx Posted September 25, 2023 Share Posted September 25, 2023 Oh I see! I guess that could work! Did you try?? I hadn't noticed that property was set on the Processor object. Link to comment Share on other sites More sharing options...
brandy Posted September 25, 2023 Author Share Posted September 25, 2023 Yeah, i forgot it too. I added following: $processor->emailTo = "{$page->parent->projekt_bautraeger->bautraeger_mail}"; As the e-mail is a pageReference-field in the parent, I have to build it like that, but it doesn´t work. The following shows me the emailadress: echo "{$page->parent->projekt_bautraeger->bautraeger_mail}"; Do you think there is a problem, as the form has recipients in the backend? All in all emailTo seems good to me: https://processwire.com/api/ref/form-builder-processor/ Link to comment Share on other sites More sharing options...
brandy Posted September 26, 2023 Author Share Posted September 26, 2023 FYI: I disabled the recipients in the backend, but it doesn´t work either! Link to comment Share on other sites More sharing options...
brandy Posted September 27, 2023 Author Share Posted September 27, 2023 @elabx Do you have an idea, what I´m doing wrong? Thanks a lot! Link to comment Share on other sites More sharing options...
elabx Posted September 27, 2023 Share Posted September 27, 2023 Hi @brandy! Could I take a look at a complete version of the hook code you are trying? If you feel like sharing the whole project with me you can DM me and maybe we'll sort it out with the real install. Link to comment Share on other sites More sharing options...
brandy Posted October 2, 2023 Author Share Posted October 2, 2023 In the head there is this: <?php $form = $forms->render('kontakt', [ 'form_page' => $page->parent->title . " " . $page->title ]); ?> And in the template there is this, which shows the form: <?php $processor = $event->object; $processor->emailSubject = "Page title is: $page->title"; $processor->emailTo = "{$page->parent->projekt_bautraeger->bautraeger_mail}"; echo $form; ?> Thanks a lot! Link to comment Share on other sites More sharing options...
elabx Posted October 2, 2023 Share Posted October 2, 2023 Ok so the second part of the code, in the template needs a hook to actually work! If you debug $processor variable, it is most likely null! So, in the head.php set this up: <?php wire()->addHookBefore("FormBuilderProcessor::emailFormReady",function($e){ /** @var InputfieldForm **/ $form = $e->arguments(0); /** @var FormBuilderEmail **/ $email = $e->arguments(1); // is this the form where we want to change the behaviour? if($form->name !== "the_form_in_question") return; $page_id = $form->getChildByName('page_with_contact_email'); if($page_id){ $page_with_contact_email = wire('pages')->get($page_id); if($page_with_contact_email->id){ $email->to = $page_with_contact_email->contact_email; } } // Not really sure if this is necessary so try putting it on and off $event->arguments(1, $email); }) $form = $forms->render('kontakt', [ 'form_page' => $page->parent->title . " " . $page->title , 'page_with_contact_email' => $page->parent->id ]); The hook code is a bit different from the previous one I posted since I realised that the contact_ Then on your template: echo $form; Let me know how it goes! Link to comment Share on other sites More sharing options...
brandy Posted October 9, 2023 Author Share Posted October 9, 2023 Thanks a lot! But I have a question - page_with_contact_email differs, depending from the site, where its send from. So I mean, I have a parent page with subpages with the different contact-email-adresses. Is this already recognized in this example? Thanks a lot! Link to comment Share on other sites More sharing options...
elabx Posted October 9, 2023 Share Posted October 9, 2023 Maybe this part should be: $form = $forms->render('kontakt', [ 'form_page' => $page->parent->title . " " . $page->title , 'page_with_contact_email' => $page->parent("contact_email!="); ]); So this part: $page->parent("contact_email!="); Should traverse upwards from the page where the form is rendering until it finds a page with the contact_email fileld. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now