Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to prevent redirection when validating with a traditional HTTP request?

Hello,

I am using server-fetched partials to fetch some data. Before the fetching, I am using basic validation inside the controller: https://laravel.com/docs/10.x/validation#quick-writing-the-validation-logic

public function getServerFetchedPartial(Request $request)
{
    $validated = $request->validate([
        'input1' => 'required|unique:posts|max:255',
        'input2' => 'required',
    ]);

    // return the data
}

Now if it passes, everything works fine and I get the data to the place I want in the blade file. However when validation fails, it returns the entire failed message to the designated area in the blade file, as seen in the docs:

If validation fails during a traditional HTTP request, a redirect response to the previous URL will be generated

In my case it's a modal, and it simply puts the entire error page inside a little modal.

How can I somehow "catch" this redirection and send custom error?

0 likes
4 replies
jlrdw's avatar

Display errors in a division. Have it hidden until you need to use it.

1 like
Ligonsker's avatar

@jlrdw the problem is that I don't even display the errors, but I think that because it does a redirect back to the previous URL, it simply fetches the entire previous page and puts it inside the modal in my case. (I see the page inside the modal, in this case, the page that launched the modal)

Please or to participate in this conversation.