Reputation: 5107
I'm trying to figure out how to properly set URL parameters to auto fill form fields in laravel
The form works and properly submits data but I have a URL like testsite.com/[email protected]&password=dK94*DFj
and I'd like to auto fill the form with the email and password from the URL
the form:
<form method="POST" action="{{ route('auth.register') }}">
<div class="reg-card reg-margin-bottom">
<div class="reg-card-content">
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required value="{{ $invitation->email }}" />
</div>
<div class="form-group">
<label for="password">New Password</label>
<input type="password" id="password" class="form-control" required name="password" />
</div>
</div>
</div>
<div class="reg-card">
<div class="reg-card-content">
<button type="submit" class="btn btn-primary btn-block">Create account</button>
</div>
</div>
</form>
Can I set this so that, as long as the params exist in the URL, then they autofill and disable those fields?
Upvotes: 1
Views: 2675
Reputation: 2621
if you want a cleaner URL, uou can create a route for the URl register.
Route::get('/register/{email?}/{hash?}',function($email,$hash){
return view("viewFile",['email'=>$email,'password'=>$hash]);
});
In your view
<form method="POST" action="{{ route('auth.register') }}">
<div class="reg-card reg-margin-bottom">
<div class="reg-card-content">
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required value="{{ $email }}" />
</div>
<div class="form-group">
<label for="password">New Password</label>
<input type="password" id="password" class="form-control" required name="password" value="{{$password}}" />
</div>
</div>
</div>
<div class="reg-card">
<div class="reg-card-content">
<button type="submit" class="btn btn-primary btn-block">Create account</button>
</div>
</div>
</form>
I don't recommend you to pass a password in the url, but if it is a hash to validate that the email is the correct one, is a good idea I do it when I want to verified that the info is not changed by the user. Also this will need to hash the email and compare the hash with the one on the url.
Upvotes: 0
Reputation: 9055
You can get it by using
{{ request()->email }}
and {{ request()->password }}
However, passing password in the url is no a good idea though!
Upvotes: 2