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

illfamed's avatar

Routing and form action help needed

Hi there,

I'm trying to pass form data to a controller function and I believe I'm either doing something wrong with the form action or with the routing. Below are three images of my form, routes and controller function. ( I can't post link yet since I've just created this account on this forum, so please replace (dot) with a .)

i(dot)imgur(dot)com/1iuI889.png

i(dot)imgur(dot)com/JmaUH84.png

i(dot)imgur(dot)com/hoTPrpC.png

This is a single page application for people to register for an event. I'm trying to save the form data into a mysql database, but when I submit the form, the data doesn't reach the controller since it doesn't return "123". Any help would be greatly appreciated.

EDIT: This is what my code looks like now

<form method="POST" action="{{ route('registreer.store') }}" class="regForm"> @csrf ...

Route::get('/', [RegistreersController::class, 'index']); Route::post('/', [RegistreersController::class, 'store'])->name('registreer.store');

public function store(Request $request) { return 123; }

EDIT #2: I fixed the issue by changing

<form method="POST" action="action="{{ route('registreer.store') ... > to <form method="POST" url="action="{{ route('registreer.store') ... >

So I had to change action= to url=

0 likes
5 replies
SilenceBringer's avatar

@illfamed move return 123 to the top of the method (before validation). Maybe your validation failed?

Check network tab of browser dev tool to see the actual response

illfamed's avatar

@SilenceBringer I tried moving "return 123" to the top of the method before validation but it didn't do anything. Here is the screenshot of the network tab of dev tools: i(dot)imgur(dot)com/2IvdF8f.png

illfamed's avatar

To all future readers, I fixed it by changing <form ... action= ...> to <form ... url=...> Thanks for the help @silencebringer you made me think harder, much appreciated.

Snapey's avatar
Snapey
Best Answer
Level 122

@illfamed this is not a solution, you just changed it so that the form does not have an action since url is not a valid attribute for forms

I think your problem is a little seen issue with laravel and posting to ''/"

It will probably work with

Route::post('/store', [RegistreersController::class, 'store'])->name('registreer.store');

<form method="POST" action="{{ route('registreer.store') }}" ... > @csrf
Ali Hamza's avatar
<form method="POST" action="{{route('Your Route name')}}" enctype="multipart/form-data"></form>

in action just pass the route name or the URl of your route that you defined in your route.php file.

Please or to participate in this conversation.