Challenge - 5 Problems
Laravel Form Input Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Blade form input code?
Consider this Laravel Blade snippet for a form input:
What will be the value attribute if the form is loaded for the first time (no previous input)?
<input type="text" name="username" value="{{ old('username', 'guest') }}" />What will be the value attribute if the form is loaded for the first time (no previous input)?
Laravel
<input type="text" name="username" value="{{ old('username', 'guest') }}" />
Attempts:
2 left
💡 Hint
Think about what the old() helper does when there is no previous input.
✗ Incorrect
The old() helper returns the previous input value if available; otherwise, it returns the default value provided as the second argument, which is 'guest' here.
❓ state_output
intermediate2:00remaining
What is the value of $request->input('email') after submitting this form?
Given this HTML form snippet:
And the Laravel controller method:
If the user changes the email input to 'newuser@example.com' before submitting, what will be returned?
<form method="POST" action="/submit"> <input type="email" name="email" value="user@example.com" /> <button type="submit">Send</button> </form>
And the Laravel controller method:
public function submit(Request $request) {
return $request->input('email');
}If the user changes the email input to 'newuser@example.com' before submitting, what will be returned?
Laravel
public function submit(Request $request) {
return $request->input('email');
}Attempts:
2 left
💡 Hint
The input value sent by the browser is what the user typed before submitting.
✗ Incorrect
The $request->input('email') returns the value sent by the form submission, which is the updated email 'newuser@example.com'.
📝 Syntax
advanced2:00remaining
Which option correctly creates a checkbox input with old value checked in Blade?
You want to create a checkbox input named 'subscribe' that remains checked if the user previously checked it. Which Blade code snippet is correct?
Attempts:
2 left
💡 Hint
Remember how to conditionally add attributes in Blade templates.
✗ Incorrect
Option A uses a ternary operator to add the 'checked' attribute only if old('subscribe') is truthy, which is the correct way.
🔧 Debug
advanced2:00remaining
Why does this Laravel form input not retain old value after validation error?
Consider this Blade input:
And the controller:
After submitting with empty title, the form reloads but the input is empty instead of showing the old input. Why?
<input type="text" name="title" value="{{ $title }}" />And the controller:
public function store(Request $request) {
$request->validate(['title' => 'required']);
// store logic
}After submitting with empty title, the form reloads but the input is empty instead of showing the old input. Why?
Attempts:
2 left
💡 Hint
Check how old input is accessed in Blade templates.
✗ Incorrect
The Blade template uses $title variable which is not automatically set to old input. Using old('title') ensures the previous input is shown.
🧠 Conceptual
expert2:00remaining
What is the main purpose of the @csrf directive in Laravel forms?
You see this directive inside a Laravel Blade form:
What does it do?
@csrf
What does it do?
Attempts:
2 left
💡 Hint
Think about security when submitting forms.
✗ Incorrect
The @csrf directive inserts a hidden input with a CSRF token that Laravel checks to prevent malicious form submissions from other sites.