Redirecting contact form to success page

Hi,

I have a contact form that on successful submission redirects to a thank you page. Both the contact page and the thank you page are in the root of the site. I am using the contact form mechanism in one of the cookbook recipes.

When all the form date has validated ok I have this section in the form controller:

            // no exception occurred, let's send a success message
            if (empty($alert) === true) {
                $success = 'Your message has been sent.';
                $data = [];
                go('contact-thank-you');
            }

On my local environment the go part works. But on the live site I have an error:

go(): Argument #1 ($func) must be a valid callback, function "contact-thank-you" not found or invalid function name

Any ideas where I am going wrong?

Thanks.

Hi,

This doesn’t look like a Kirby issue. The error message gives it away:

go(): Argument #1 ($func) must be a valid callback

Kirby’s go() helper takes a URL string, not a callback. So the go() running on your live site isn’t Kirby’s. Something in that environment defines a global go(callable $func) (a PHP extension or a library) and Kirby’s helper never gets registered. That’s also why it works locally but fails on the server.

You can confirm it with:

<?php
$go = new ReflectionFunction('go');

echo $go->isInternal()
	? 'internal, extension: ' . $go->getExtensionName()
	: 'userland, file: ' . $go->getFileName();

If it points anywhere other than kirby/config/helpers.php, that’s your conflict.

As a workaround you can call the class directly instead of the helper:

\Kirby\Cms\Response::go(page('contact-thank-you')->url());