How to redirect Form with error using #parameter pointing back to the form in the browser

about a year ago

mkoula
Generous Backer | 34
+
0
-

I have quite a long page and at the bottom is the form.
If the form is successful then I redirect to the page I want with #hash, but how to do it if the form has some errors through the validation on the server side? Is there any possible way? Unless I am redirected to the top of the page…

Last edited by mkoula (2018-08-17 18:18)

about a year ago

Martk
Member | 515
+
+1
-
// onAnchor is called when presenter is attached
$form->onAnchor[] = function (Form $form): void {
    $presenter = $form->getPresenter();
    $form->setAction($presenter->link('this#' . $form->getElementPrototype()->id)); // changes attribute action in form
};

you can use as helper

FormHelpers::htmlAnchor($form);

// in FormHelpers
function htmlAnchor(Form $form): void {
    $form->onAnchor[] = function (Form $form): void {
        $presenter = $form->getPresenter();
        $form->setAction($presenter->link('this#' . $form->getElementPrototype()->id));
    };
}

Last edited by Martk (2018-08-18 16:47)