Skip to content

Commit 9c18f9e

Browse files
author
Laurent Marquet
authored
Merge pull request #2 from 975L/issue1
Corrections to issue #1
2 parents 3c6c782 + 3368894 commit 9c18f9e

File tree

5 files changed

+38
-26
lines changed

5 files changed

+38
-26
lines changed

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
v1.8.3
4+
------
5+
- Removed Bootstrap javascript request as not needed (21/07/2018)
6+
- Corrected gdpr checkbox display as it was disaplyed even if false is set (21/07/2018)
7+
- Removed `SubmitType` in FormType and replaced by adding button in template as it's not a "Best Practice" (Revert of v1.8.1) (21/07/2018)
8+
- Removed `Action` in controller method name as not requested anymore (21/07/2018)
9+
- Renamed variable `$contact` to `$contactForm` in Controller (21/07/2018)
10+
- Corrected meta in `layout.html.twig` (21/07/2018)
11+
312
v1.8.2.1
413
--------
514
- Removed required in composer.json (22/05/2018)

Controller/ContactFormController.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ContactFormController extends Controller
2727
* name="contactform_display")
2828
* @Method({"GET", "HEAD", "POST"})
2929
*/
30-
public function displayAction(Request $request)
30+
public function display(Request $request)
3131
{
3232
//Gets subject if passed by url parameter "s"
3333
$subject = filter_var($request->query->get('s'), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
@@ -49,20 +49,23 @@ public function displayAction(Request $request)
4949
}
5050

5151
//Defines contact
52-
$contact = new ContactForm();
53-
$contact
52+
$contactForm = new ContactForm();
53+
$contactForm
5454
->setName($name)
5555
->setEmail($userEmail)
5656
->setSubject($subject)
5757
;
5858

5959
//Dispatch event
6060
$dispatcher = $this->get('event_dispatcher');
61-
$event = new ContactFormEvent($contact);
61+
$event = new ContactFormEvent($contactForm);
6262
$dispatcher->dispatch(ContactFormEvent::CREATE_FORM, $event);
6363

6464
//Defines form
65-
$form = $this->createForm(ContactFormType::class, $contact, array('receiveCopy' => $event->getReceiveCopy()));
65+
$form = $this->createForm(ContactFormType::class, $contactForm, array(
66+
'receiveCopy' => $event->getReceiveCopy(),
67+
'gdpr' => $this->getParameter('c975_l_contact_form.gdpr'),
68+
));
6669
$form->handleRequest($request);
6770

6871
if ($form->isSubmitted() && $form->isValid()) {

Form/ContactFormType.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Symfony\Component\Form\FormBuilderInterface;
1414
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
1515
use Symfony\Component\Form\Extension\Core\Type\EmailType;
16-
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
1716
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
1817
use Symfony\Component\Form\Extension\Core\Type\TextType;
1918
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -62,17 +61,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
6261
))
6362
;
6463
}
65-
$builder
66-
->add('gdpr', CheckboxType::class, array(
67-
'label' => 'text.gdpr',
68-
'required' => true,
69-
'mapped' => false,
70-
))
71-
->add('submit', SubmitType::class, array(
72-
'label' => 'label.send',
73-
'attr' => array('class' => 'btn btn-block btn-lg btn-primary'),
74-
))
75-
;
64+
if ($options['gdpr'] === true) {
65+
$builder
66+
->add('gdpr', CheckboxType::class, array(
67+
'label' => 'text.gdpr',
68+
'required' => true,
69+
'mapped' => false,
70+
));
71+
}
7672
}
7773

7874
public function configureOptions(OptionsResolver $resolver)
@@ -83,6 +79,9 @@ public function configureOptions(OptionsResolver $resolver)
8379
'translation_domain' => 'contactForm',
8480
));
8581

86-
$resolver->setRequired('receiveCopy');
82+
$resolver
83+
->setRequired('receiveCopy')
84+
->setRequired('gdpr')
85+
;
8786
}
8887
}

Resources/views/forms/contact.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
{# Form #}
1212
{{ form_start(form) }}
1313
{{ form_widget(form) }}
14+
{# Submit#}
15+
<div class="form-group">
16+
<button type="submit" name="submit" title="{{ 'label.send'|trans }}" class="btn btn-lg btn-primary btn-block">
17+
{{ 'label.send'|trans }}
18+
</button>
19+
</div>
1420
{{ form_end(form) }}
1521
{# Mandatory field #}
1622
<p class="text-muted">

Resources/views/layout.html.twig

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
{% spaceless %}
44
<!DOCTYPE html>
5+
<html lang="{{ app.request.locale }}">
56
<head>
67
{% block head %}
78
<meta charset="utf-8" />
8-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
9-
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=no" />
9+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
10+
<meta name="viewport" content="width=device-width initial-scale=1.0" />
1011
<meta name="format-detection" content="telephone=no" />
1112
<title>{{ 'label.contact'|trans }}</title>
1213
<base />
1314
{# Css #}
1415
{% block css %}
1516
{# Uses c975L/IncludeLibraryBundle #}
1617
{{ inc_lib('bootstrap', 'css', '3.*') }}
17-
{{ inc_lib('fontawesome', 'css', '5.*') }}
18-
{% endblock %}
19-
{# Javascript #}
20-
{% block javascript %}
21-
{# Uses c975L/IncludeLibraryBundle #}
22-
{{ inc_lib('bootstrap', 'js', '3.*') }}
2318
{% endblock %}
2419
{% endblock %}
2520
</head>

0 commit comments

Comments
 (0)