1

HTML:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<!-- Suggest Modal -->
    <div id="suggestModal" class="modal fade anycard-modal" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" id="modal-close" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Business Suggestion</h4>
                </div>
                <div class="modal-body">
                    <div id="suggest-area">
                        <form id="suggestion-form">
                            <div class="form-group">
                                <span class="aster">*</span>
                                <label for="s-name">Name:</label>
                                <input type="text" class="form-control" id="s-name">
                            </div>
                            <div class="form-group">
                                <span class="aster">*</span>
                                <label for="s-email">Email:</label>
                                <input type="text" class="form-control" id="s-email">
                            </div>
                            <div class="form-group">
                                <span class="aster">*</span>
                                <label for="s-idea">Business suggestion:</label>
                                <textarea class="form-control" id="s-idea"></textarea>
                            </div>
                            <div class="form-group">
                                <div class="g-recaptcha" data-sitekey="6LdoqQoUAAAAAHNBx5GxMXYq_8FfxZMUf09bn7QI"></div>
                            </div>
                            <button type="submit" class="btn btn-primary">Submit your suggestion</button>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div><!-- /Suggest Modal -->

I am facing the problem with google reCAPTCHA. It's not loading properly. Then i inspect the browser and see the problem occurs on iframe. It's source is undefined.

<iframe src="undefined?autoplay=1" title="recaptcha widget" width="304" height="78" role="presentation" frameborder="0" scrolling="no" name="undefined"></iframe>

The Ajax code is given below which i used or form submit. Ajax:

$('#suggestion-form').submit(function(e) {
    e.preventDefault();
    var form_data = new FormData();
    var name = $('#s-name').val();
    var email = $('#s-email').val();
    var suggestion = $('#s-idea').val();

    form_data.append('name', name);
    form_data.append('email', email);
    form_data.append('suggestion', suggestion);

    $.ajax({
    url: 'default.php?controller=queries&action=addsuggestion',
    type: 'POST',
    data: form_data,
    processData: false,
    contentType: false,
    success: function(data) {
        if(data.success) {
        $('#suggest-area')
            .find('.alert').remove()
            .end()
            .prepend('<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>Thank you for your valuable suggestion</div>');
        window.setTimeout(function(){
            //$('#suggestModal').modal('hide');
            $('#modal-close').click();
            $('#suggestion-form')[0].reset();
            $('#suggest-area').find('.alert').remove();
        }, 2000);
        }else{
        var error = '';

        switch(data.error) {
            case 'fillFields':
                error = 'Please fill in all the fields';
            break;
            case 'invalidEmail':
                error = 'The provided email is invalid';
            break;
        }
        $('#suggest-area')
            .find('.alert').remove()
            .end()
            .prepend('<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><strong>Error:</strong> '+error+'.</div>');

        }
    }
    });

i can't understand why the iframe src is undefined. reCAPTCHA is not loading properly because of the undefined source of iframe. Please help me to solve this problem.

Saleh Ahmad Oyon
  • 672
  • 1
  • 6
  • 20
  • Where is iframe, it is not in html. From where you got? – Kumar Oct 31 '16 at 12:39
  • I think it data-sitekey should be a full link and your key should be a parameter of that link, are you sure you have to put directly only your key? – Antonios Tsimourtos Oct 31 '16 at 14:31
  • @Kumar If you inspect your browser then you will find an iframe inside the .g-recaptcha div. In the iframe src will be like https://www.google.com/recaptcha/api2/anchor?k=6Ld3rg8TAAAAACGH7e9bMjc8f8ZIPFRBoRwh9r0v&co=aHR0cDovL2NvbnZlbnRpb24ubm9vYmxvbmVseS5jb206ODA.&hl=en&v=r20161028135114&theme=dark&size=normal&cb=euw3c0vwy12o . But in my code, the value of the src attr is "undefined?autoplay=1" – Saleh Ahmad Oyon Oct 31 '16 at 15:11
  • @Tony Here is the doc for google reCAPTCHA v2: https://developers.google.com/recaptcha/docs/display . In there i have found the html code to integrate reCAPTCHA. – Saleh Ahmad Oyon Oct 31 '16 at 15:20
  • @SalehAhmadOyon this is the solution http://stackoverflow.com/questions/29822607/uncaught-referenceerror-grecaptcha-is-not-defined – Antonios Tsimourtos Oct 31 '16 at 15:23
  • @Tony Unortunately, it's not working in my case. I have tried it earlier. – Saleh Ahmad Oyon Nov 01 '16 at 04:38

0 Answers0