Skip to content

Commit 6c86a55

Browse files
committed
feature #816 Add help messages to some form fields (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Add help messages to some form fields One of my favourite new Symfony 4.1 features. It's amazing and it looks like this in the Demo app: ![form-help](https://user-images.githubusercontent.com/73419/41594526-fa670158-73c3-11e8-9044-3cf8a2f6a26d.png) Commits ------- 5afae21 Add help messages to some form fields
2 parents 644d543 + 5afae21 commit 6c86a55

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/Form/CommentType.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use App\Entity\Comment;
1515
use Symfony\Component\Form\AbstractType;
16+
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
1617
use Symfony\Component\Form\FormBuilderInterface;
1718
use Symfony\Component\OptionsResolver\OptionsResolver;
1819

@@ -40,7 +41,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4041
// $builder->add('content', null, ['required' => false]);
4142

4243
$builder
43-
->add('content')
44+
->add('content', TextareaType::class, [
45+
'help' => 'Comments not complying with our Code of Conduct will be moderated.',
46+
])
4447
;
4548
}
4649

src/Form/PostType.php

+3
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4848
'label' => 'label.title',
4949
])
5050
->add('summary', TextareaType::class, [
51+
'help' => 'Summaries can\'t contain Markdown or HTML contents; only plain text.',
5152
'label' => 'label.summary',
5253
])
5354
->add('content', null, [
5455
'attr' => ['rows' => 20],
56+
'help' => 'Use Markdown to format the blog post contents. HTML is allowed too.',
5557
'label' => 'label.content',
5658
])
5759
->add('publishedAt', DateTimePickerType::class, [
5860
'label' => 'label.published_at',
61+
'help' => 'Set the date in the future to schedule the blog post publication.',
5962
])
6063
->add('tags', TagsInputType::class, [
6164
'label' => 'label.tags',

templates/blog/_comment_form.html.twig

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
{{ form_errors(form.content) }}
2929

3030
{{ form_widget(form.content, {attr: {rows: 10}}) }}
31+
{{ form_help(form.content) }}
3132
</div>
3233

3334
<div class="form-group">

0 commit comments

Comments
 (0)