genemu / GenemuFormBundle

Extra Form : Captcha GD, Tinymce, Recaptcha, JQueryDate, JQueryAutocomplete, JQuerySlider, JQueryFile, JQueryImage
587 stars 263 forks source link

Error Load Repcath #231

Closed LorenzoGodino closed 11 years ago

LorenzoGodino commented 11 years ago

Hi all! I I have been ours part of Google Recaptcha and dont working because this part of script :(jquery_layout.html.twigs)

    if (window.addEventListener) {
        window.addEventListener('load', Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }}), false);
    } else if (window.attachEvent) {
        window.attachEvent('onload', Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }}));
    } else if (document.getElementById{{ id }}_div) {
        window.onload = Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }});
    }

not entry.I replaced with : $(document).ready(function(){
$(function(){ Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw}});
}); }); });

and now working... Do you have any thing??

bamarni commented 11 years ago

Hi @LorenzoGodino,

As recaptcha doesn't require jquery in order to work, I'd prefer keeping it to pure javascript, I use jquery for this so I don't really know the best cross-browser way to achieve the same thing in javascript.

Where did you grab the code snippet from above? This is not generated from GenemuFormBundle, currently it only generates your first line with window.addEventListener, according to http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the , the javascript code snippet you've pasted is the equivalent to what jQuery.ready() does, in which browser doesn't it work?

bamarni commented 11 years ago

oh it's on the 2.0 branch (@c01d99c3c3c79ea6e67ebad73d5af11fd2f41dba), I should definitely cherry-pick it to master, I'd be curious to know your browser and its version as it should be cross-browser apparently.

LorenzoGodino commented 11 years ago

I've tried this too and not work. I think the my solution is very simple and definitive although not is jquery only is pure javascript

LorenzoGodino commented 11 years ago

And not work in mozilla 18.0.3 and chrome last version I repeat the code full for this is our interesting {% spaceless %} <script type="text/javascript" src="{{ asset("https://www.google.com/recaptcha/api/js/recaptcha_ajax.js") }}">

{% endspaceless %} if you prefered jquery :

jQuery(document).ready(function($) { Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw}}); });

please changed this...

bamarni commented 11 years ago

your both code snippets are using jQuery, could you do a gist with a full HTML page example where it fails (the client generated part)?

LorenzoGodino commented 11 years ago

this is my code:

My Config.yml genemu_form: recaptcha: public_key: "XXXXX" private_key: "XXX" enabled: true server_url: 'http://www.google.com/recaptcha/api' ssl: use: true server_url: 'http://www.google.com/recaptcha/api'

My Config_test.yml

genemu_form: recaptcha: test_mode: true

My form

use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface;

use Etecnologic\PortalWeb\FrontEndBundle\Entity\Contacto; class ContactType extends AbstractType{ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('nombre','text'); $builder->add('telefonocontacto'); $builder->add('email','email'); $builder->add('mensaje','textarea' );

    $settings=array ('configs' => array(
                                    'theme' => 'white',
                                    'lang' => 'es'
                                    ),
                'validator' => array('timeout' => 30),
                'label'=>'Eres Humano?',

    );

    $builder->add('recaptcha', 'genemu_recaptcha',$settings);

My Controler

public function contactoAction() {
    $em = $this->getDoctrine()->getManager();
    $contenidos = $em
            ->getRepository('xxx:Paginaweb')
            ->devuelveContenidoPage('Contacto');
    $form = $this->createForm(new ContactType(), new Contactos());
    $request = $this->get('request');
    return $this->render('xxx:Web:contacto.html.twig',
                                            array('form' => $form->createView(),
                                                    'contenidos' => $contenidos,));
}

My view:

{% extends 'xxx::layout.html.twig' %} {% block stylesheets %} {{ parent() }} {{ form_stylesheet(form) }} {% endblock %} {% block javascripts %} {{ parent() }} {{ form_javascript(form) }} {% endblock %}

{% block content %}

{%for contenido in contenidos%}
{%if contenido.classType=='title' %}

{{contenido.value}}

{% endif %} {%if contenido.classType=='subtitle' %}

{{contenido.value}}

{% endif %} {%if contenido.classType=='label' %}

{{contenido.value}}

{% endif %} {%if contenido.classType=='mail' %} {{contenido.value}} {% endif %} {%if contenido.classType=='googlemap' %}
Ver Etecnologic en un mapa más grande {% endif %}
{% endfor %} ```
``` {% block form_row %} {% spaceless %}
{{ form_widget(form) }}
{% endspaceless %} {% endblock form_row %}

{% endblock %}

with this:

if (window.addEventListener) {
    window.addEventListener('load', Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }}), false);
} else if (window.attachEvent) {
    window.attachEvent('onload', Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }}));
} else if (document.getElementById{{ id }}_div) {
    window.onload = Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }});
}

the page generated is:

<style type="text/css">.recaptchatable td img{display:block}.recaptchatable .recaptcha_r1_c1{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') 0 -63px no-repeat;width:318px;height:9px}.recaptchatable .recaptcha_r2_c1{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -18px 0 no-repeat;width:9px;height:57px}.recaptchatable .recaptcha_r2_c2{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -27px 0 no-repeat;width:9px;height:57px}.recaptchatable .recaptcha_r3_c1{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') 0 0 no-repeat;width:9px;height:63px}.recaptchatable .recaptcha_r3_c2{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -18px -57px no-repeat;width:300px;height:6px}.recaptchatable .recaptcha_r3_c3{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -9px 0 no-repeat;width:9px;height:63px}.recaptchatable .recaptcha_r4_c1{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -43px 0 no-repeat;width:171px;height:49px}.recaptchatable .recaptcha_r4_c2{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -36px 0 no-repeat;width:7px;height:57px}.recaptchatable .recaptcha_r4_c4{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -214px 0 no-repeat;width:97px;height:57px}.recaptchatable .recaptcha_r7_c1{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -43px -49px no-repeat;width:171px;height:8px}.recaptchatable .recaptcha_r8_c1{background:url('http://www.google.com/recaptcha/api/img/white/sprite.png') -43px -49px no-repeat;width:25px;height:8px}.recaptchatable .recaptcha_image_cell center img{height:57px}.recaptchatable .recaptcha_image_cell center{height:57px}.recaptchatable .recaptcha_image_cell{background-color:white;height:57px}#recaptcha_area,#recaptcha_table{width:318px!important}.recaptchatable,#recaptcha_area tr,#recaptcha_area td,#recaptcha_area th{margin:0!important;border:0!important;padding:0!important;border-collapse:collapse!important;vertical-align:middle!important}.recaptchatable *{margin:0;padding:0;border:0;font-family:helvetica,sans-serif;font-size:8pt;color:black;position:static;top:auto;left:auto;right:auto;bottom:auto;text-align:left!important}.recaptchatable #recaptcha_image{margin:auto}.recaptchatable img{border:0!important;margin:0!important;padding:0!important}.recaptchatable a,.recaptchatable a:hover{outline:none;border:0!important;padding:0!important;text-decoration:none;color:blue;background:none!important;font-weight:normal}.recaptcha_input_area{position:relative!important;width:146px!important;height:45px!important;margin-left:20px!important;margin-right:5px!important;margin-top:4px!important;background:none!important}.recaptchatable label.recaptcha_input_area_text{margin:0!important;padding:0!important;position:static!important;top:auto!important;left:auto!important;right:auto!important;bottom:auto!important;background:none!important;height:auto!important;width:auto!important}.recaptcha_theme_red label.recaptcha_input_area_text,.recaptcha_theme_white label.recaptcha_input_area_text{color:black!important}.recaptcha_theme_blackglass label.recaptcha_input_area_text{color:white!important}.recaptchatable #recaptcha_response_field{width:145px!important;position:absolute!important;bottom:7px!important;padding:0!important;margin:0!important;font-size:10pt}.recaptcha_theme_blackglass #recaptcha_response_field,.recaptcha_theme_white #recaptcha_response_field{border:1px solid gray}.recaptcha_theme_red #recaptcha_response_field{border:1px solid #cca940}.recaptcha_audio_cant_hear_link{font-size:7pt;color:black}.recaptchatable{line-height:1em}#recaptcha_instructions_error{color:red!important}

.recaptcha_is_showing_audio .recaptcha_only_if_image,.recaptcha_isnot_showing_audio .recaptcha_only_if_audio,.recaptcha_had_incorrect_sol .recaptcha_only_if_no_incorrect_sol,.recaptcha_nothad_incorrect_sol .recaptcha_only_if_incorrect_sol{display:none !important}