Add anchor link in controller

hello,

i have used Bastian Allgeiers Gist to make a contact form.
the form is on the bottom of the page so my question:

is it possible to add a “#contactform” anchor to the URL in the controller?
the page should scroll down to the form again after sending the mail.

Any hints?

 // try to send it
 if($email->send()) {
   //go('home');
  $alert = array("Message sent. Thank you.");
 // add the error to the alert list if it failed
 } else {
   $alert = array($email->error());
 }
   }
 }
 return compact('alert');

Also the “CSRF” token is always wrong. dunno why. in the form i set it, check the session… it’s ok.
After sending, in the controller, the CSRF token is changed somewhere and does not match anymore… strange.
Marked it out for now… 1st question is more important atm.

thx,
Sven

No need to put an anchor link in the controller, just put the id of the section in the action attribute, e.g.

<form class="contact-form" action="<?php echo $site->url()?>/#contact" method="post">
2 Likes

:bow:

thank you very much!

Does this still work in Kirby 3 ? I am trying to the same but the controller does not work if there is an anchor in the action attribute.

Apparently it works like that:

<form class="contact-form" action="<?php echo $site->url()?>#contact" method="post">

without the /

maybe its a Windows thing.