Browse Source

[Accueil et Boutique] Formulaire de contact : ajout d'un captcha

develop
Guillaume Bourgeois 1 week ago
parent
commit
924f49b8bb
5 changed files with 143 additions and 11 deletions
  1. +2
    -3
      common/forms/ContactForm.php
  2. +2
    -1
      composer.json
  3. +137
    -1
      composer.lock
  4. +1
    -3
      frontend/views/site/contact.php
  5. +1
    -3
      producer/views/site/contact.php

+ 2
- 3
common/forms/ContactForm.php View File

@@ -53,6 +53,7 @@ class ContactForm extends Model
public $subject;
public $body;
public $verifyCode;
public $reCaptcha;
public $isTest;

/**
@@ -64,9 +65,7 @@ class ContactForm extends Model
[['name', 'email', 'subject', 'body'], 'required', 'message' => 'Champs obligatoire'],
['email', 'email', 'message' => 'Email incorrect'],
['isTest', 'string'],
['verifyCode', 'captcha', 'message' => 'Veuillez recopier le code de vérification', 'when' => function($model) {
return $model->isTest != 'isTest';
}],
['reCaptcha', \himiklab\yii2\recaptcha\ReCaptchaValidator::className()]
];
}


+ 2
- 1
composer.json View File

@@ -39,7 +39,8 @@
"ext-curl": "*",
"yiisoft/yii2-twig": "^2.4",
"letyii/yii2-tinymce": "dev-master",
"yiisoft/yii2-bootstrap5": "^2.0"
"yiisoft/yii2-bootstrap5": "^2.0",
"himiklab/yii2-recaptcha-widget": "*"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",

+ 137
- 1
composer.lock View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e73b7f03dc724fab379b3e68f99bb0dd",
"content-hash": "8c1037174be24d68a6c94faa6227f48d",
"packages": [
{
"name": "2amigos/yii2-chartjs-widget",
@@ -1080,6 +1080,59 @@
],
"time": "2022-06-20T21:43:03+00:00"
},
{
"name": "himiklab/yii2-recaptcha-widget",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/himiklab/yii2-recaptcha-widget.git",
"reference": "341ae7e19e12783f3dfd8984a49185e0a44021ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/himiklab/yii2-recaptcha-widget/zipball/341ae7e19e12783f3dfd8984a49185e0a44021ea",
"reference": "341ae7e19e12783f3dfd8984a49185e0a44021ea",
"shasum": ""
},
"require": {
"yiisoft/yii2": "~2.0.11",
"yiisoft/yii2-httpclient": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.34"
},
"type": "yii2-extension",
"autoload": {
"psr-4": {
"himiklab\\yii2\\recaptcha\\": "src/",
"himiklab\\yii2\\recaptcha\\tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "HimikLab",
"homepage": "https://github.com/himiklab/"
}
],
"description": "Yii2 Google reCAPTCHA v2 and v3 widget",
"keywords": [
"captcha",
"google",
"recaptcha",
"widget",
"yii2"
],
"support": {
"issues": "https://github.com/himiklab/yii2-recaptcha-widget/issues",
"source": "https://github.com/himiklab/yii2-recaptcha-widget"
},
"abandoned": true,
"time": "2019-05-14T07:40:36+00:00"
},
{
"name": "justcoded/yii2-event-listener",
"version": "1.0.2",
@@ -3170,6 +3223,89 @@
],
"time": "2020-06-24T00:04:01+00:00"
},
{
"name": "yiisoft/yii2-httpclient",
"version": "2.0.15",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-httpclient.git",
"reference": "5a8350e15f2db3555ba52830c9c701587c136e87"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-httpclient/zipball/5a8350e15f2db3555ba52830c9c701587c136e87",
"reference": "5a8350e15f2db3555ba52830c9c701587c136e87",
"shasum": ""
},
"require": {
"paragonie/random_compat": ">=1",
"yiisoft/yii2": "~2.0.13"
},
"require-dev": {
"cweagans/composer-patches": "^1.7",
"phpunit/phpunit": "4.8.34"
},
"type": "yii2-extension",
"extra": {
"patches": {
"phpunit/phpunit": {
"Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch",
"Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch"
},
"phpunit/phpunit-mock-objects": {
"Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch"
}
},
"branch-alias": {
"dev-master": "2.0.x-dev"
},
"composer-exit-on-patch-failure": true
},
"autoload": {
"psr-4": {
"yii\\httpclient\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Paul Klimov",
"email": "klimov.paul@gmail.com"
}
],
"description": "HTTP client extension for the Yii framework",
"keywords": [
"curl",
"http",
"httpclient",
"yii2"
],
"support": {
"forum": "http://www.yiiframework.com/forum/",
"irc": "irc://irc.freenode.net/yii",
"issues": "https://github.com/yiisoft/yii2-httpclient/issues",
"source": "https://github.com/yiisoft/yii2-httpclient",
"wiki": "http://www.yiiframework.com/wiki/"
},
"funding": [
{
"url": "https://github.com/yiisoft",
"type": "github"
},
{
"url": "https://opencollective.com/yiisoft",
"type": "open_collective"
},
{
"url": "https://tidelift.com/funding/github/packagist/yiisoft/yii2-httpclient",
"type": "tidelift"
}
],
"time": "2023-05-22T18:32:24+00:00"
},
{
"name": "yiisoft/yii2-jui",
"version": "2.0.7",

+ 1
- 3
frontend/views/site/contact.php View File

@@ -65,9 +65,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<?= $form->field($model, 'reCaptcha')->widget(\himiklab\yii2\recaptcha\ReCaptcha::className())->label('') ?>
<?= $form->field($model, 'isTest')->hiddenInput() ?>
<div class="form-group submit">
<?= Html::submitButton('<i class="bi bi-send-fill"></i> Envoyer', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>

+ 1
- 3
producer/views/site/contact.php View File

@@ -55,9 +55,7 @@ $this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDe
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?php echo $form->field($model, 'verifyCode')->widget(yii\captcha\Captcha::className(), [
'template' => '<div class="row"><div class="col-md-12">{image}</div><div class="col-md-12">{input}</div></div>',
]); ?>
<?= $form->field($model, 'reCaptcha')->widget(\himiklab\yii2\recaptcha\ReCaptcha::className())->label('') ?>
<?= $form->field($model, 'isTest')->hiddenInput() ?>
<div class="form-group form-buttons">
<?= Html::submitButton('<i class="bi bi-send"></i> Envoyer', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>

Loading…
Cancel
Save