#When the controller method returns validation errors, show popup

1 messages · Page 1 of 1 (latest)

cinder fable
#

Hi there, i have a page, on that page is a button "share contact details". It just shows a form with JS, and the form has a normal behaviour ```php
public function createCustomCard(Request $request){
$data = $request->validate([
'name' => 'required',
'phone' => 'required',
'email' => 'required'
]);
//successful form submittion code will come here

    return redirect()->back();
}``` it redirects back with the right errors, when fields are left empty, but what is a good way to check if there are any errors to send some sort of value back that automatically makes that popup form appear when you get redirected with errors?
cyan dagger
#

I don't understand the use-case here, if you're making a request through JS you should apply the appropriate headers (such as requesting JSON), then you'll receive those errors. And it doesn't make sense to redirect a JSON request

cinder fable
#

i basically have a page /profile/jan. There's a button "share contact details", which opens a form with js basically form.classList.remove('hiddne')' it just has a form action which leads to a controller method. When fields are left empty, you get back to /profile/jan with the form errors. But the form is hidden again since that is the normal behaviour, because "hidden" has not been removed yet since the page reloaded and hidden is active on the form again