Jump to content

Formbuilder - one form, different recipients


brandy
 Share

Recommended Posts

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

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

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

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!

  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...