New form type which is not captcha really. Bugfix for exception.

This commit is contained in:
Alexey Skobkin 2015-10-14 06:53:54 +03:00
parent bec53995a0
commit 07126b5586
6 changed files with 65 additions and 4 deletions

View file

@ -29,6 +29,8 @@ framework:
twig: twig:
debug: "%kernel.debug%" debug: "%kernel.debug%"
strict_variables: "%kernel.debug%" strict_variables: "%kernel.debug%"
form_themes:
- 'SkobkinCopyPasteBundle:Form:fields.html.twig'
# Assetic Configuration # Assetic Configuration
assetic: assetic:

View file

@ -30,6 +30,12 @@ class CopypasteController extends Controller
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isValid()) { if ($form->isValid()) {
// Check "captcha"
// @todo check internally in transformation or somewhere else
if (null === $form->get('captcha')->getData()) {
throw $this->createNotFoundException('This isn\'t the service you\'re spamming to.');
}
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
if ($form->get('private')->getData()) { if ($form->get('private')->getData()) {
@ -57,7 +63,7 @@ class CopypasteController extends Controller
} }
} }
throw new $this->createAccessDeniedException('Sorry :('); throw $this->createAccessDeniedException('Sorry :(');
} }
/** /**

View file

@ -66,6 +66,10 @@ class CopypasteType extends AbstractType
}, },
//'preferred_choices' => [] //'preferred_choices' => []
]) ])
->add('captcha', 'skobkin_fake_captcha', [
'mapped' => false,
'required' => true,
])
->add('actions', 'form_actions') ->add('actions', 'form_actions')
; ;
} }

View file

@ -0,0 +1,32 @@
<?php
namespace Skobkin\Bundle\CopyPasteBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FakeCaptchaType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => false,
]);
}
public function getParent()
{
return 'hidden';
}
public function getName()
{
return 'skobkin_fake_captcha';
}
}

View file

@ -1,4 +1,5 @@
services: services:
# skobkin_copy_paste.example: copypaste.form.type.fake_captcha:
# class: Skobkin\Bundle\CopyPasteBundle\Example class: Skobkin\Bundle\CopyPasteBundle\Form\FakeCaptchaType
# arguments: [@service_id, "plain_value", %parameter%] tags:
- { name: form.type, alias: skobkin_fake_captcha }

View file

@ -0,0 +1,16 @@
{% block skobkin_fake_captcha_widget %}
{% spaceless %}
<div id="{{ form.vars.id }}"></div>
<script type="text/javascript">
(function () {
div = document.getElementById('{{ form.vars.id }}');
input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', '{{ form.vars.full_name }}');
input.setAttribute('value', 'dumb_text');
div.appendChild(input);
console.log(div);
})();
</script>
{% endspaceless %}
{% endblock %}