So i have a very basic controller located at : app/Http/Controllers/RentalRequestController
namespace AppHttpControllers; use IlluminateRoutingController as BaseController; class RentalRequestController extends BaseController { public function store(Request $request, $obj) { $g = 0; return view("success"); } }
Then in my web.php
i have the following:
Route::Post('/', 'RentalRequestController@store');
And then i have the following form in my view:
<form id="rentalForm" name="rentalForm" role="form" action="/" method="post"> <!-- Row --> <div class="f-row"> <div class="form-group one-fourth"> <label for="address">Gade</label> <input type="text" name="address" id="address" data-parsley-required-message="Indtast venligst din gade" required data-parsley-errors-container="#errAddress"/> <div class="full-width"> <label id="errAddress"></label> </div> </div> <div class="form-group one-fourth"> <label for="number">Husnummer</label> <input type="number" name="number" id="number" data-parsley-required-message="Indtast venligst dit husnummer" required="" data-parsley-errors-container="#errNumber"> <div class="full-width" style=""> <label id="errNumber"></label> </div> </div> <div class="form-group one-fourth"> <label for="zip">Postnr</label> <input type="text" name="zip" id="zip" required="" data-parsley-required-message="Indtast venligst dit postnr" data-parsley-length-message="Indtast et dansk postnr" data-parsley-length="[4,4]" data-parsley-zip="dk" data-parsley-errors-container="#errZip"> <div class="full-width" style=""> <label id="errZip"></label> </div> </div> <div class="form-group one-fourth"> <label for="city">By</label> <input type="text" name="city" id="city" required="" data-parsley-required-message="Indtast venligst din by" data-parsley-errors-container="#errCity"> <div class="full-width" style=""> <label id="errCity"></label> </div> </div> </div> <!-- //Row --> <!-- Row --> <div class="f-row"> </div> <!-- //Row --> <div class="f-row"> <div class="form-group one-fourth"> <label for="kvm">kvadratmeter</label> <input type="number" id="kvm" min="1" class="uniform-input number" name="kvm" required="" data-parsley-required-message="Indtast venligst arealet på din bolig" data-parsley-errors-container="#errKvm"> <div class="full-width" style=""> <label id="errKvm"></label> </div> </div> <div class="form-group one-fourth"> <label for="price">Nuværende husleje</label> <input type="number" id="price" name="price" step="0.01" required="" data-parsley-required-message="Indtast venligst din nuværende husleje" data-parsley-errors-container="#errPrice"> <div class="full-width" style=""> <label id="errPrice"></label> </div> </div> <div class="form-group select one-fourth"> <label for="concatSelector">Vælg kontakt form</label> <div class="selector"> <select id="concatSelector" required="" data-parsley-required-message="Indtast venligst din nuværende husleje"> <option selected="">Vælg kontakt form</option> <option value="cell">Telefon</option> <option value="mail">E-mail</option> </select> </div> </div> <div class="form-group one-fourth fadeIn" id="selectEmail"> <label for="email">Kontakt information</label> <input type="email" id="email" name="email" placeholder="E-mail" required="" data-parsley-type="email" data-parsley-type-message="Indtast venligst en gyldig e-mail" data-parsley-required-message="Indtast venligst en gyldig e-mail" data-parsley-errors-container="#errEmail" > <div class="full-width" style=""> <label id="errEmail"></label> </div> </div> <div class="form-group one-fourth fadeIn" id="selectCell"> <label for="mobile">Kontakt information</label> <input type="number" id="mobile" name="phone" placeholder="Telefon" required="" data-parsley-required-message="Indtast venligst et gyldig telefon nr." data-parsley-errors-container="#errCell" > <div class="full-width" style=""> <label id="errCell"></label> </div> </div> </div> <div class="f-row"> <div class="form-group right one-fourth" style="margin-top: 35px"> <button type="button" onclick="sendInformation()" class="btn large black">Kan jeg spare penge? </button> </div> </div>
Now when i submit the form it redirects me to a page saying:
The page has expired due to inactivity. Please refresh and try again.
Can anyone tell me what ive done wrong?
Advertisement
Answer
You should add:
{{ csrf_field() }}
inside <form>
element for example like this:
<form id="rentalForm" name="rentalForm" role="form" action="/" method="post"> {{ csrf_field() }}
This is called CSRF protection