Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 9401c2b

Browse files
author
maxence d'Espeuilles
committed
captcha as option + Fix bug in json response
1 parent 1a08317 commit 9401c2b

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

Entity/Webform.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ class Webform
7575
* @ORM\Column(name="use_ajax", type="boolean")
7676
*/
7777
private $useAjax;
78+
79+
/**
80+
* @var bool
81+
*
82+
* @ORM\Column(name="use_captcha", type="boolean")
83+
*/
84+
private $useCaptcha = 0;
7885

7986
/**
8087
* @ORM\ManyToOne(targetEntity="Mdespeuilles\MailBundle\Entity\Email")
@@ -245,5 +252,19 @@ public function setSenderMail($senderMail)
245252
{
246253
$this->senderMail = $senderMail;
247254
}
255+
256+
/**
257+
* @return mixed
258+
*/
259+
public function isUseCaptcha() {
260+
return $this->useCaptcha;
261+
}
262+
263+
/**
264+
* @param mixed $useCaptcha
265+
*/
266+
public function setUseCaptcha($useCaptcha) {
267+
$this->useCaptcha = $useCaptcha;
268+
}
248269
}
249270

Form/WebformType.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4747
$builder->add($this::camelCase($component->getName()), $component->getType(), $componentOptions);
4848
}
4949

50-
$builder->add('recaptcha', EWZRecaptchaType::class, [
51-
"required" => true,
52-
"label" => false,
53-
"mapped" => false
54-
]);
50+
if ($webform->isUseCaptcha()) {
51+
$builder->add('recaptcha', EWZRecaptchaType::class, [
52+
"required" => true,
53+
"label" => false,
54+
"mapped" => false
55+
]);
56+
}
5557

5658
$builder->add('submit', SubmitType::class, [
5759
'label' => $webform->getSubmitString()

Resources/config/webform_admin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ easy_admin:
2525
- { property: 'components', type: 'collection', type_options: { entry_type: 'Mdespeuilles\WebformBundle\Form\WebformComponentType', by_reference: false } }
2626
- { type: 'group', css_class: 'col-sm-6', label: 'Paramètres avancés' }
2727
- { property: 'useAjax', label: 'Utiliser ajax pour la soumission du formulaire' }
28+
- { property: 'useCaptcha', label: 'Utiliser un captcha pour le formulaire' }
2829
- { type: 'group', css_class: 'col-sm-6', label: 'Paramètres emails' }
2930
- { property: 'senderMail', label: 'Adresse email de l''expediteur' }
3031
- { property: 'emailTemplate', label: 'Template', help: 'd''email à utiliser pour envoyer les resultats' }
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ var ajax = function (url, data) {
44
req.onreadystatechange = function (aEvt) {
55
if (req.readyState == 4) {
66
if (req.status == 200) {
7-
console.log(req.response);
8-
document.querySelector('.webform .response').innerHTML = req.response;
7+
document.querySelector('.webform .response').innerHTML = JSON.parse(req.response);
98
}
109
else {
1110
console.log(req.response);

0 commit comments

Comments
 (0)