I am new to Laravel and I'm having trouble with posting data to a controller. I couldn't find the corresponding documentation. I want to something similar in Laravel that I do in C# MVC.
<form action="/someurl" method="post">
<input type="text" name="someName" />
<input type="submit">
</form>
Controller
[HttpPost]
public ActionResult SomeUrl(string someName)
{
...
}
And also validate form data before submit to controller using jQuery validation in laravel. First of all download or install laravel 8 new setup. So, open terminal and type the following command to install new laravel 8 app into your machine: In this step, setup database with your downloded/installed laravel 8 app.
If your form is going to accept file uploads, add a files option to your array: Laravel provides an easy method of protecting your application from cross-site request forgeries.
This laravel 8 form request validation ajax tutorial will create contact us form and post or submit form data on controller using jQuery ajax. And also validate form data before submit to controller using jQuery validation in laravel.
So, find create_posts_table.php file inside LaravelForm/database/migrations/ directory. Then open this file and add the following code into function up () on this file: Now, open again your terminal and type the following command on cmd to create tables into your selected database:
You should use route.
your .html
<form action="{{url('someurl')}}" method="post">
<input type="text" name="someName" />
<input type="submit">
</form>
in routes.php
Route::post('someurl', 'YourController@someMethod');
and finally in YourController.php
public function someMethod(Request $request)
{
dd($request->all()); //to check all the datas dumped from the form
//if your want to get single element,someName in this case
$someName = $request->someName;
}
This works best
<form action="{{url('someurl')}}" method="post">
@csrf
<input type="text" name="someName" />
<input type="submit">
</form>
in web.php
Route::post('someurl', 'YourController@someMethod');
and in your Controller
public function someMethod(Request $request)
{
dd($request->all()); //to check all the datas dumped from the form
//if your want to get single element,someName in this case
$someName = $request->someName;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With