Roman
January 5, 2022, 10:41am
1
I have contact form as block, in which I want to have field for email, so that editor can set, who will get webform submission. How to print that email in controller?
Thinking about this, but it tells “Call to undefined function controller()”
<?php controller('default', [
'sendemail' => $block->sendemail(),
] ) ?>
I don’t understand your question.
As the error says, there is no controller()
function. Where are you using this piece of code? What is in your default controller.
Please state exactly what you are trying to do.
Roman
August 23, 2022, 7:50am
3
Still need this. I have a block with contact form. User can edit labels, and I want to add ability for user to write, to which email form should be sent.
And the question is, how can I take this value and print it in controller?
I know how to take value from site blueprint, it works like this:
$sendemail = $site->formemail();
...
$kirby->email([
'template' => 'contactform',
'from' => 'no_reply@example.com',
'replyTo' => $data['email'],
'to' => "$sendemail",
But don’t understand, how to take it from block.
Roman
September 13, 2022, 6:48am
4
Is question clear now, could you help with this please?
texnixe
September 13, 2022, 10:54am
5
No, still information missing.
To me, it seems this block can be about anywhere. So how would you know in your controller which block to use?
Roman
September 14, 2022, 6:34am
6
This block is used in template default.php
, so I guess controller can take value of that field from page?
texnixe
September 14, 2022, 6:38am
7
Well, you can filter all block by this one type:
$contactFormBlock = $page->blocks()->filterBy('type', 'contact')->first();
$emailReceiver = $contactFormBlock ? $contactFormBlock->to() : 'fallback value'; // whatever the field is called
Will only work if there is only one such block.
Roman
September 14, 2022, 6:48am
8
Thanks, this gives: The form could not be sent: “” is not a valid email address
texnixe
September 14, 2022, 7:31am
9
Well, check what you get as $emailReceiver. Make sure you use the right field names, I only guessed something
Roman
September 14, 2022, 7:39am
10
Gives empty. Double checked field name, it’s right.
texnixe
September 14, 2022, 7:49am
11
Ok, that line was nonsense
$contactFormBlock = $page->fieldname()->toBlocks()->filterBy('type', 'contact')->first();
Roman
September 14, 2022, 7:58am
12
Tried this:
$contactFormBlock = $page->myblocks()->toBlocks()->filterBy('type', 'contactform')->first();
$emailReceiver = $contactFormBlock ? $contactFormBlock->to() : 'test@example.com';
returns only fallback value.