I work with laravel9 I bought your template with which I work but I have a problem, I created an add form based on your design, which means that I have to fill in the fields step by step, I realized that you use stepper, how do I send the data to my controller?
Hi Komla,
To send the data from your stepper-based form to your Laravel controller, you can use JavaScript to gather all the form inputs and send them through AJAX. Axios is a JavaScript library for making HTTP requests and can be used for this purpose.
You can refer to this js file for example using stepper.
/resources/_keenthemes/src/js/custom/utilities/modals/create-account.js
Here's a basic example to get all form inputs:
- Create a JavaScript function that gathers the form data and sends it to your Laravel controller via AJAX. Below is a basic example using Axios:
// Assuming you have a button with id "submitBtn" that triggers the form submission
document.getElementById("submitBtn").addEventListener("click", function() {
// Get all form inputs
var formData = new FormData(document.getElementById("yourFormId"));
// Make an AJAX request using Axios
axios.post("/your-controller-endpoint", formData)
.then(function (response) {
// Handle the response if needed
console.log(response);
})
.catch(function (error) {
// Handle errors if any
console.error(error);
});
});
public function yourControllerMethod(Request $request)
{
// Access form data using $request
$data = $request->all();
// Process and save the data as needed
// ...
// Return a response if needed
return response()->json(["message" => "Data received successfully"]);
}