Dynamic data in config.php

I’m using AJAX to send an email using Uniform, so my ‘to’ and ‘from’ are set in the config file. The ‘to’ email should be set in the panel, but it doesn’t seem to work as I expect.

                'to' => $page('page')->emailField(),
                'from' => 'from@website-form.de',

I also tried esc(), but still didn’t work (the form works fine if I simply write an email address here). Is it even possible to use data in a config file like this?

What does this do?

It might be better to store email addresses in the site.txt as an email-field (e.g. contactemail) and make it editable for your editors (or not) via the site.yml blueprint? Then you can retrieve it like this: $site->contactemail() in your form controller

FYI: $page is a variable that refers to the current page, you can’t use it as a function.

There is a page() helper function that takes the path to the page as parameter, e.g. page('blog') or page('notes/across-the-ocean'). So don’t mix this up.

And yes, you can set arbitrary options in your config

return [
  // some other options
  'my.wonderful.email' => 'me@example.com',
  // some more options

You can then fetch such options with option('my.wonderful.email').

Doh, just a syntax error. This works:

    'to' => esc(page('kontakt')->emailField()),
    'from' => 'from@website-form.de',

Thanks guys!