Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc53c7c

Browse files
committed
Added a note about client-side and server-side form validation
1 parent aaf72b2 commit bc53c7c

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

app/Resources/views/admin/blog/_form.html.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
{#
2+
By default, forms enable client-side validation. This means that you can't
3+
test the server-side validation errors from the browser. To temporarily
4+
disable this validation, add the 'novalidate' attribute:
5+
6+
{{ form_start(form, { attr: { novalidate: 'novalidate' } }) }}
7+
#}
8+
19
{{ form_start(form) }}
210
{{ form_widget(form) }}
311

app/Resources/views/blog/comment_form.html.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
{#
2+
By default, forms enable client-side validation. This means that you can't
3+
test the server-side validation errors from the browser. To temporarily
4+
disable this validation, add the 'novalidate' attribute:
5+
6+
{{ form_start(form, { method: ..., action: ..., attr: { novalidate: 'novalidate' } }) }}
7+
#}
8+
19
{{ form_start(form, { method: 'POST', action: path('comment_new', { 'postSlug': post.slug }) }) }}
210
{# instead of displaying form fields one by one, you can also display them
311
all with their default options and styles just by calling to this function:

src/AppBundle/Form/CommentType.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class CommentType extends AbstractType
3232
*/
3333
public function buildForm(FormBuilderInterface $builder, array $options)
3434
{
35+
// By default, form fields include the 'required' attribute, which enables
36+
// the client-side form validation. This means that you can't test the
37+
// server-side validation errors from the browser. To temporarily disable
38+
// this validation, set the 'required' attribute to 'false':
39+
//
40+
// $builder->add('content', null, array('required' => false));
41+
3542
$builder
3643
->add('content')
3744
;

src/AppBundle/Form/PostType.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ class PostType extends AbstractType
2929
*/
3030
public function buildForm(FormBuilderInterface $builder, array $options)
3131
{
32-
// for the full reference of options defined by each form field type
32+
// For the full reference of options defined by each form field type
3333
// see http://symfony.com/doc/current/reference/forms/types.html
34+
35+
// By default, form fields include the 'required' attribute, which enables
36+
// the client-side form validation. This means that you can't test the
37+
// server-side validation errors from the browser. To temporarily disable
38+
// this validation, set the 'required' attribute to 'false':
39+
//
40+
// $builder->add('title', null, array('required' => false, ...));
41+
3442
$builder
3543
->add('title', null, array('label' => 'label.title'))
3644
->add('summary', 'textarea', array('label' => 'label.summary'))

0 commit comments

Comments
 (0)