Click here to Skip to main content
15,174,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I've been struggling to find the way to resolve this error since I'm new to Laravel. Here is my code:

The form in buy.blade.php:
<form action="{{ route('purchase'}}" method="post" role="form">
     {{ csrf_field() }}
         <h3 class="registration-title">Registration Form</h3>
             <div class="form">
                  <div class="form-group">
                       <div class="form-wrapper-1">
                            <label for="">First Name</label>
                            <input type="text" class="get-name-1">
                       </div>
                  <div class="form-wrapper-1">
                       <label for="">Last Name</label>
                       <input type="text" class="get-name-2">
                  </div>
             </div>
                  <div class="form-wrapper-2">
                       <label for="">Email</label>
                       <input type="text" class="form-control">
                  </div>
                  <div class="form-wrapper-2">
                       <label for="">Credit Card</label>
                       <input type="password" class="form-control">
                  </div>
                  <div class="form-wrapper-2">
                       <label for="">Password</label>
                       <input type="password" class="form-control">
                  </div>
                  <div class="checkbox">
                       <label>
                            <input type="checkbox"> I accept the Terms of Use & Privacy Policy.
                                
                            </label>
                       </div>
                  </div>
                    <button class="register-button" onclick="location.href='{{'submit'}}'">Register Now</button>
                </form>


The route (web.php):
Route::post('/buy',function()
{
    return view('Buy.buyrope');
});
Route::post('submit','InputStreamReader@save')->name('purchase');


The functions in Controller InputStreamReader:
public function save(Request $request)
    {
        print_r($request->input());
        $customer = new Customers();
        $customer->First_Name = $request->First_Name;
        $customer->Last_Name = $request->Last_Name;
        $customer->Email = $request->Email;
        $customer->Credit_Card = $request->Credit_Card;
        $customer->Password = $request->Password;
        echo $customer->save();
    }


So I want to navigate from the site "localhost/merchant" to "localhost/buy" if a button is clicked. But when clicking the button to navigate to "buy.blade.php", I obtain an error
The GET method is not supported for this route. Supported methods: POST.


What I have tried:

I also changed from get to post but it still pops out the same error and it's been several days I couldn't fix this bug and I even did like what some sites say about this error but nothing changed. Please help me. I still don't fully understand the route and navigate mechanics in Laravel 8.
Posted
Updated 16-Aug-21 0:59am
v2

1 solution

Quote:
HTML
<button class="register-button" onclick="location.href='{{'submit'}}'">Register Now</button>
When you click your button, you throw away anything the user has entered into the form, and make a GET request to the "submit" route.

Instead, you need to submit the form. Change the form's action to the correct route. Remove the onclick from the button, and change it's type to submit:
HTML
<form action="{{'submit'}}" method="post">
    ...
    <button type="submit">Register Now</button>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900