@@ -218,57 +218,14 @@ this by setting ``use_referer`` to true (it defaults to false):
218
218
),
219
219
));
220
220
221
- Control the Redirect URL from inside the Form
222
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223
-
224
- You can also override where the user is redirected to via the form itself by
225
- including a hidden field with the name ``_target_path ``. For example, to
226
- redirect to the URL defined by some ``account `` route, use the following:
227
-
228
- .. configuration-block ::
229
-
230
- .. code-block :: html+twig
231
-
232
- {# src/AppBundle/Resources/views/Security/login.html.twig #}
233
- {% if error %}
234
- <div>{{ error.message }}</div>
235
- {% endif %}
236
-
237
- <form action="{{ path('login') }}" method="post">
238
- <label for="username">Username:</label>
239
- <input type="text" id="username" name="_username" value="{{ last_username }}" />
240
-
241
- <label for="password">Password:</label>
242
- <input type="password" id="password" name="_password" />
243
-
244
- <input type="hidden" name="_target_path" value="account" />
245
-
246
- <input type="submit" name="login" />
247
- </form>
248
-
249
- .. code-block :: html+php
250
-
251
- <!-- src/AppBundle/Resources/views/Security/login.html.php -->
252
- <?php if ($error): ?>
253
- <div><?php echo $error->getMessage() ?></div>
254
- <?php endif ?>
255
-
256
- <form action="<?php echo $view['router']->generate('login') ?>" method="post">
257
- <label for="username">Username:</label>
258
- <input type="text" id="username" name="_username" value="<?php echo $last_username ?>" />
259
-
260
- <label for="password">Password:</label>
261
- <input type="password" id="password" name="_password" />
262
-
263
- <input type="hidden" name="_target_path" value="account" />
264
-
265
- <input type="submit" name="login" />
266
- </form>
221
+ Redirecting on Login Failure
222
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
223
268
- Now, the user will be redirected to the value of the hidden form field. The
269
- value attribute can be a relative path, absolute URL, or a route name. You
270
- can even change the name of the hidden form field by changing the ``target_path_parameter ``
271
- option to another value.
224
+ In addition to redirecting the user after a successful login, you can also set
225
+ the URL that the user should be redirected to after a failed login (e.g. an
226
+ invalid username or password was submitted). By default, the user is redirected
227
+ back to the login form itself. You can set this to a different route (e.g.
228
+ ``login_failure ``) with the following config:
272
229
273
230
.. configuration-block ::
274
231
@@ -282,7 +239,8 @@ option to another value.
282
239
main :
283
240
# ...
284
241
form_login :
285
- target_path_parameter : redirect_url
242
+ # ...
243
+ failure_path : login_failure
286
244
287
245
.. code-block :: xml
288
246
@@ -299,7 +257,7 @@ option to another value.
299
257
300
258
<firewall name =" main" >
301
259
<!-- ... -->
302
- <form-login target -path-parameter = " redirect_url " />
260
+ <form-login failure -path= " login_failure " />
303
261
</firewall >
304
262
</config >
305
263
</srv : container >
@@ -314,20 +272,68 @@ option to another value.
314
272
'main' => array(
315
273
// ...
316
274
'form_login' => array(
317
- 'target_path_parameter' => 'redirect_url',
275
+ // ...
276
+ 'failure_path' => 'login_failure',
318
277
),
319
278
),
320
279
),
321
280
));
322
281
323
- Redirecting on Login Failure
324
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282
+ Control the Redirect URL from inside the Form
283
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
325
284
326
- In addition to redirecting the user after a successful login, you can also set
327
- the URL that the user should be redirected to after a failed login (e.g. an
328
- invalid username or password was submitted). By default, the user is redirected
329
- back to the login form itself. You can set this to a different route (e.g.
330
- ``login_failure ``) with the following config:
285
+ You can also override where the user is redirected to via the form itself by
286
+ including a hidden field with the name ``_target_path `` for success and
287
+ ``_failure_path `` for failure. For example, to redirect to the URL defined
288
+ by some ``account `` route, use the following:
289
+
290
+ .. configuration-block ::
291
+
292
+ .. code-block :: html+twig
293
+
294
+ {# src/AppBundle/Resources/views/Security/login.html.twig #}
295
+ {% if error %}
296
+ <div>{{ error.message }}</div>
297
+ {% endif %}
298
+
299
+ <form action="{{ path('login') }}" method="post">
300
+ <label for="username">Username:</label>
301
+ <input type="text" id="username" name="_username" value="{{ last_username }}" />
302
+
303
+ <label for="password">Password:</label>
304
+ <input type="password" id="password" name="_password" />
305
+
306
+ <input type="hidden" name="_target_path" value="account" />
307
+ <input type="hidden" name="_failure_path" value="login" />
308
+
309
+ <input type="submit" name="login" />
310
+ </form>
311
+
312
+ .. code-block :: html+php
313
+
314
+ <!-- src/AppBundle/Resources/views/Security/login.html.php -->
315
+ <?php if ($error): ?>
316
+ <div><?php echo $error->getMessage() ?></div>
317
+ <?php endif ?>
318
+
319
+ <form action="<?php echo $view['router']->path('login') ?>" method="post">
320
+ <label for="username">Username:</label>
321
+ <input type="text" id="username" name="_username" value="<?php echo $last_username ?>" />
322
+
323
+ <label for="password">Password:</label>
324
+ <input type="password" id="password" name="_password" />
325
+
326
+ <input type="hidden" name="_target_path" value="account" />
327
+ <input type="hidden" name="_failure_path" value="login" />
328
+
329
+ <input type="submit" name="login" />
330
+ </form>
331
+
332
+ Now, the user will be redirected to the value of the hidden form field. The
333
+ value attribute can be a relative path, absolute URL, or a route name.
334
+ You can even change the name of the hidden form field by changing the
335
+ ``target_path_parameter `` and ``failure_path_parameter `` options to another
336
+ value.
331
337
332
338
.. configuration-block ::
333
339
@@ -341,8 +347,8 @@ back to the login form itself. You can set this to a different route (e.g.
341
347
main :
342
348
# ...
343
349
form_login :
344
- # ...
345
- failure_path : login_failure
350
+ target_path_parameter : redirect_url
351
+ failure_path_parameter : redirect_url
346
352
347
353
.. code-block :: xml
348
354
@@ -359,7 +365,8 @@ back to the login form itself. You can set this to a different route (e.g.
359
365
360
366
<firewall name =" main" >
361
367
<!-- ... -->
362
- <form-login failure-path =" login_failure" />
368
+ <form-login target-path-parameter =" redirect_url" />
369
+ <form-login failure-path-parameter =" redirect_url" />
363
370
</firewall >
364
371
</config >
365
372
</srv : container >
@@ -374,8 +381,8 @@ back to the login form itself. You can set this to a different route (e.g.
374
381
'main' => array(
375
382
// ...
376
383
'form_login' => array(
377
- // ...
378
- 'failure_path ' => 'login_failure ',
384
+ 'target_path_parameter' => 'redirect_url',
385
+ 'failure_path_parameter ' => 'redirect_url ',
379
386
),
380
387
),
381
388
),
0 commit comments