ContactBundle
ContactBundle copied to clipboard
Disable Captcha not working
I followed the config in issue https://github.com/mremi/ContactBundle/issues/7:
mremi_contact:
form:
captcha_disabled: true
captcha_type: genemu_captcha
Still the Captcha appears in dev.
Checking $this->captchaDisabled in
https://github.com/mremi/ContactBundle/blob/master/Form/Type/ContactType.php#L91
returns false via VarDumper.
The last time I worked on the project it seemed to work. I recently updated to Symfony 2.6 - mabye it has changed since this update.
Hi @webdevilopers ,
I just check it with the same configuration you give here and it works with Symfony 2.6.x-dev b0d73f3. What's your Symfony version?
I'm sure my problem is based on my injection. I use a custom form class that was extending the ContactType. Though I injected the argument for captchaDisabled it was not accessed since the property of the extendend class was set to private. I changed them to protected for testing and everthing works when injecting:
And I guess I get the last error because of my 2.6 version problem I will have to solve first. It should disappear then.
I guess my problems start when injecting my custom form class:
<service id="acme.contact_request_form_type" class="Acme\AppBundle\Form\ContactRequestType">
<tag name="form.type" alias="contact_request_form" />
<argument type="service" id="mremi_contact.subject_provider.noop"></argument>
<argument>Mremi\ContactBundle\Model\Contact</argument>
<argument>true</argument>
<argument>genemu_captcha</argument>
</service>
But I would like to use the value from the config.yml in order to disable captcha only in dev:
mremi_contact:
store_data: true
# contact_class: Mremi\ContactBundle\Model\Contact
contact_class: Acme\AppBundle\Entity\ContactRequest
form:
# type: mremi_contact
type: contact_request_form
name: contact_form
validation_groups: [ContactRequest]
# validation_groups: [Default]
subject_provider: mremi_contact.subject_provider.noop
captcha_disabled: true
captcha_type: genemu_captcha # or genemu_recaptcha
How can I access it in my service?
You can't access the config outside the bundle extension.
I think we could:
- add a parameter in
form.xmlto allow the user to replace the default class (so no need to redo the injection unless you need something else) - change the visibility of properties from private to protected in
ContactType
What do you think?
Sorry for the late response @mremi . Havn't been working on the project for a long time.
With current dev-master I use this service to override the bundle:
<service id="sps_web.contact_request_form_type" class="Sps\Bundle\ContactUsBundle\Form\ContactRequestType">
<tag name="form.type" alias="contact_request_form" />
<argument type="service" id="mremi_contact.subject_provider.noop"></argument>
<argument>Sps\Bundle\ContactUsBundle\Entity\ContactRequest</argument>
<argument>genemu_captcha</argument>
</service>
I've seen some other issues so far:
- https://github.com/mremi/ContactBundle/pull/21
- https://github.com/genemu/GenemuFormBundle/issues/181
The captcha_disabled was removed I think.
What is the best way to disable the captcha for dev now?
Should I use config_dev and config_prod and configure both keys genemu_form and mremi_contact there? Do we have an example in the docs?
Hi @webdevilopers !
Yep, captcha_disabled has been removed: if you don't fill the captcha_type node, no captcha will be added to the form. So if you want to disable the captcha for the dev env (ie enable it only for prod), you have to use the config*.yml files like this for instance:
# app/config/config.yml used for common configs for all env
mremi_contact:
form:
type: contact_request_form
email:
to: [email protected]
# app/config/config_prod.yml
mremi_contact:
form:
captcha_type: genemu_captcha
Thanks for the hint @mremi . I tried your config and passed an empty 3rd argument via service since I need my custom form:
<service id="sps_web.contact_request_form_type" class="Sps\Bundle\ContactUsBundle\Form\ContactRequestType">
<tag name="form.type" alias="contact_request_form" />
<argument type="service" id="mremi_contact.subject_provider.noop"></argument>
<argument>Sps\Bundle\ContactUsBundle\Entity\ContactRequest</argument>
<argument>genemu_captcha</argument>
</service>
Unfortunately no captcha shows up. I guess I have to pass the parameter from the config as 3rd argument?
Yep or CaptchaType::class if you are using Symfony 2.8+ (with PHP 5.5+, else Genemu\Bundle\FormBundle\Form\Core\Type\CaptchaType).
I guess you extend the base type of this bundle, if not and if you are the final user of this service, you don't need to inject these arguments, use them as it in the service, more simple.
Could you give an example of how to get my custom form working without injecting? Because
<service id="sps_web.contact_request_form_type" class="Sps\Bundle\ContactUsBundle\Form\ContactRequestType">
<tag name="form.type" alias="contact_request_form" />
<!-- <argument type="service" id="mremi_contact.subject_provider.noop"></argument>
<argument>Sps\Bundle\ContactUsBundle\Entity\ContactRequest</argument>
<argument>%mremi_contact.form.captcha_type%</argument>-->
</service>
causes the constructor to fail: Argument 1 passed to Mremi\ContactBundle\Form\Type\ContactType::__construct() must be an instance of Mremi\ContactBundle\Provider\SubjectProviderInterface, none given
My config for dev:
mremi_contact:
store_data: true
# contact_class: Mremi\ContactBundle\Model\Contact
contact_class: Sps\Bundle\ContactUsBundle\Entity\ContactRequest
form:
type: contact_request_form
name: contact_form
validation_groups: [ContactRequest]
# validation_groups: [Default]
subject_provider: mremi_contact.subject_provider.noop
# captcha_type: false
Thanks in advance @mremi !
This exception is threw because your ContactRequestType extends the ContactType which requires some dependencies, see my previous comment.
Sorry @mremi , I still don't get it. Could you post me the service example I have to use in order to use my own form class and the config settings of the captcha_type depending on the envorinment?