Laravel 7.x - Pass parameter in url to register form

Viewed 289

I would like to pass email adress as parameter in url to register page.

I tried http://myapp.test/register?email=jonhsnow@myapp.com but email wasn't filled in form.

I don't know if Laravel protec this url. How can I do this? Is there another way?

Regards

2 Answers

It won't fill the email input field by itself, you will have to do it manually.

You can use the request() helper and populate the input like this:

<input type="email" name="email" id="email" value="{{ old('email', request('email')) }}" required>

This way it will populate the input when you provide it as a parameter in the URL, and it will keep the value when there is a validation error with old().

From the docs:

request()

The request function returns the current request instance or obtains an input item:

$request = request();

$value = request('key', $default);

old()

The old function retrieves an old input value flashed into the session:

$value = old('value');

$value = old('value', 'default');

Use your controller to pass the email string. Or pass the entity that contains the email. If you pass an entity, use $YourEntity->getEmail() in your webpage to get the email you need

Related