Insert data with form validation using ajax in laravel
Created at 06-Jul-2021 ,
By samar
Insert data with form validation using ajax in laravel
With this article, we’ll look at some examples of how to address the "Insert data with form validation using ajax in laravel" problem.
This code snippet will help you to insert data if the form request is validated and return validation error messages using ajax in laravel view if the form is not validated.-
Insert data with form validation and show validation error if not validated using ajax in laravel 8
//routes\web.php Route::view('/ajax/index', 'ajax/index'); Route::post('/ajax/store', 'AjaxController@store')->name('contact.store'); //resources\views\ajax\index.blade.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="description" content="Free Web tutorials"> <meta name="keywords" content="HTML, CSS, JavaScript"> <meta name="author" content="John Doe"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>w3codegenerator</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"/> </head> <body> <div class="container"> <div class="row"> <div class="col-md-6 offset-3"> <form method="post" id="addNewContactForm" action="{{ route('contact.store') }}"> @csrf <h3> Add Contact Details </h3> <div id="ajaxResp" class="alert" style="display:none;"></div> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" id="name" name="name" /> <div id="nameError" class="error"></div> </div> <div class="form-group"> <label for="mobile">Mobile</label> <input type="text" class="form-control" name="mobile" id="mobile"/> <div id="mobileError" class="error"></div> </div> <div class="form-group"> <label for="email">Email</label> <input type="email" class="form-control" name="email" id="email" /> <div id="emailError" class="error"></div> </div> <div class="form-group"> <label for="addressOne">Address Line 1 </label> <textarea class="form-control" name="address_line_1" id="addressOne">
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to check record exist or not in relationship table
- First and last item of the array using foreach iteration in laravel blade
- Eager loading dynamically in laravel
- How to create pivot table in laravel using migration
- The openssl extension is required for SSL/TLS protection but is not available
- How to pass two variables in HREF in laravel
- How to validate URL with https using regex in laravel
- Generate random string lowercase in Laravel
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- How to check column value of a record is null or not in laravel
- How to return a column with different name in Laravel
- Route prefix with auth middleware in laravel
- Laravel 10 starter app using breeze on live server
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- How to check records exist in loaded relationship in Laravel blade view
- Get previous date data in laravel
- Get current month records in laravel 7/8
- How to upload image in laravel 8
- How to send email in laravel
- Count all and get 10 records after where condition in laravel
- How to make Copy or Duplicate table row in laravel
- How to display pivot table column value in laravel
- Class 'App\Providers\Auth' not found
- Laravel onclick function not working
- Attempt to read property "avatar" on null in Laravel