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:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'SkobkinCopyPasteBundle:Form:fields.html.twig'
# Assetic Configuration
assetic:

View File

@ -30,6 +30,12 @@ class CopypasteController extends Controller
$form->handleRequest($request);
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();
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' => []
])
->add('captcha', 'skobkin_fake_captcha', [
'mapped' => false,
'required' => true,
])
->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:
# skobkin_copy_paste.example:
# class: Skobkin\Bundle\CopyPasteBundle\Example
# arguments: [@service_id, "plain_value", %parameter%]
copypaste.form.type.fake_captcha:
class: Skobkin\Bundle\CopyPasteBundle\Form\FakeCaptchaType
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 %}