0
0
Laravelframework~20 mins

Form input in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Laravel Form Input Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Blade form input code?
Consider this Laravel Blade snippet for a form 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') }}" />
AThe value will be an empty string.
BThe value will be null.
CThe value will be 'username'.
DThe value will be 'guest'.
Attempts:
2 left
💡 Hint
Think about what the old() helper does when there is no previous input.
state_output
intermediate
2:00remaining
What is the value of $request->input('email') after submitting this form?
Given this HTML form snippet:
<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');
}
A'newuser@example.com'
Bnull
C'user@example.com'
DAn error is thrown
Attempts:
2 left
💡 Hint
The input value sent by the browser is what the user typed before submitting.
📝 Syntax
advanced
2: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?
A<input type="checkbox" name="subscribe" {{ old('subscribe') ? 'checked' : '' }} />
B<input type="checkbox" name="subscribe" checked="{{ old('subscribe') }}" />
C<input type="checkbox" name="subscribe" value="checked" {{ old('subscribe') }} />
D<input type="checkbox" name="subscribe" value="1" checked="old('subscribe')" />
Attempts:
2 left
💡 Hint
Remember how to conditionally add attributes in Blade templates.
🔧 Debug
advanced
2:00remaining
Why does this Laravel form input not retain old value after validation error?
Consider this Blade input:
<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?
ABecause the validate method clears old input automatically.
BBecause $title is not set to old('title') in the Blade template.
CBecause the input name is incorrect.
DBecause the form method is GET instead of POST.
Attempts:
2 left
💡 Hint
Check how old input is accessed in Blade templates.
🧠 Conceptual
expert
2:00remaining
What is the main purpose of the @csrf directive in Laravel forms?
You see this directive inside a Laravel Blade form:
@csrf

What does it do?
AIt encrypts the form data before sending it to the server.
BIt validates the form inputs automatically on the server.
CIt adds a hidden input with a token to protect against cross-site request forgery attacks.
DIt styles the form inputs with default CSS.
Attempts:
2 left
💡 Hint
Think about security when submitting forms.