@daisha
In Laravel, you can access the submitted data in the same form using the old()
function.
Here's an example of how to use it:
1
|
<input type="text" name="username" value="{{ old('username') }}" /> |
This will populate the input field with the submitted value if there is one, otherwise it will be empty.
Dropdown:
1 2 3 4 |
<select name="role"> <option value="admin" {{ old('role') == 'admin' ? 'selected' : '' }}>Admin</option> <option value="user" {{ old('role') == 'user' ? 'selected' : '' }}>User</option> </select> |
Checkbox:
1
|
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }} /> |
Radio button:
1 2 |
<input type="radio" name="gender" value="male" {{ old('gender') == 'male' ? 'checked' : '' }} /> Male <input type="radio" name="gender" value="female" {{ old('gender') == 'female' ? 'checked' : '' }} /> Female |
By using the old()
function, you can ensure that the submitted data is displayed in the same form after a validation error or when you want to display the previously submitted data.