Error after Submit form

Hi Guys,
i am new with kirby and have a problem with it or maybe it is my php knowledge too…

I try to “rebuild” the contact form because we changed our webserver from a local vm to azure(“App Service”) and a few problem with the new smtp-situation(send mails).
At the beginning we used Kirby Uniform but i want to change it with custom php code(sendGrid/O365 Mail API, etc.)

i know have the snippet(site\snippets\contactForm.php):

<div class="mod modForm">
    <div class="inner">
        <h2>Kontaktformular</h2>


		<form action="<?php echo $page->url() ?>" method="POST">

            <p class="small">
                This is a test
            </p>

            <?php echo csrf_field() ?>
            <?php echo honeypot_field() ?>
			
            <button class="btn btn-primary" name="demo" type="submit">Nachricht absenden</button>			
        </form>
    </div>
</div>

and the controller(site\controllser\contact.php):

<?php


return function ($site, $pages, $page)
{
	if(isset($_POST['demo']))
	{
		echo $page->url();
		echo "<script type='text/javascript'>confirm('hello')</script>";
		
//here i want to do my smtp stuff later
		
		echo "<script type='text/javascript'>window.location = '/kontakt'</script>";
		
	};
};

?>

when i try to do the normal “header(‘location: URL’)” it is not working. I get the error “This page is currently offline due to an unexpected error. We are very sorry for the inconvenience and will fix it as soon as possible.”

i also tried “Header::redirect(URL)” → no success

the only thing which worked is “window.location” from Javascript. But i then cant parse my error-variable back to the snippet.

I hope you can help me… i am very frustrated now…
Thanks!

Leon

I suggest you first enable debugging to find out what the error is or check your php error logs

hi @texnixe
thanks for the response.

thats another problem… i cant get it work too.
wether in Azure or in XAMPP.

<?php


return [
    'debug'  => true
];

/*

---------------------------------------
License Setup
---------------------------------------

Please add your license key, which you've received
via email after purchasing Kirby on http://getkirby.com/buy

It is not permitted to run a public website without a
valid license key. Please read the End User License Agreement
for more information: http://getkirby.com/license

*/

c::set('license', 'K2-PRO-xxx');
c::set('panel.install', true);

This is my config.php

You’re mixing up Kirby 3 syntax with Kirby 2 syntax here. c::set() is Kirby 2, the return array Kirby 3. Since you have chosen the Kirby 2 category, you would have to set

c:: set('debug', true);

ahhh thas makes sense.

now i get following message:

After google this error i found a solution…
Put “session_start();” at the beginning of the code solved the issue.

But why did it worked with Uniform/Form?
Does they start the “session” in their library?

I don’t know, but it seems it’s still loading uniform stuff and you are still echoing the csrf and honeypot fields from the plugin. Somehow, that doesn’t really seem to fit together and doesn’t make sense.

Good to know…

its because i used the uniform stuff as template and removed the “for me not important parts”.
It’s not very nice i know, but i am at the beginning of learning Kirby and the general syntax of php.
I will try to make it more clear.

But anyway… my main-problem is solved!
Thanks!

By the way: this was the most fastest response/help i’ve ever recieved for forum posts! Great Job