0

I have a wordpress custom theme that started giving a weird error out from the blue.

Every time you post a comment it will return a javascript alert with all the content of the page.

I haven't made any changes to the theme that would have effect in this so I have no idea why is this happening, I tried removing all the javascript of the theme, updating the comments related files in the server (the same error happens locally) and replacing the comments.php with a generic template or using <?php comment_form(); ?> instead of <?php comments_template(); ?>.

You can test it in http://www.faf.fi/uutiset/faf-international-ohjaajakoulutukset-alkavat-pian/ (text in Finnish, Nimi = Name, Sähköposti = Email).

Any ideas?

1 Answer 1

1

I tried removing all the javascript of the theme, updating the comments related files in the server (the same error happens locally)

The problem is a result of this file(you obviously didn't disable that one in testing).
http://www.faf.fi/wp-content/themes/faf/scripts/js/functions.js

Blocking that script in my browser resolves the issue, but i think it's this area of the script specifically that's failing..

    $('form').submit( function(){

        var form = $(this);

        if ( validateForm( this ) ) {

            $.post(
                form.attr('action'),        //url   A string containing the URL to which the request is sent
                form.serialize(),           //data  A map or string that is sent to the server with the request.

                //success   A callback function that is executed if the request succeeds
                function(response, status, request){
                    // do something with response
                    alert( stripTags(response) );
                }

                //dataType  The type of data expected from the server (text, xml, json)
            );
        }
        //Prevent default
        return false;
    });

The alert you're seeing is generated by that function. I have no idea what the cause of your issue is nor how to resolve it(i'm no JS expert), but i'm pretty certain this function is the source of your problem.

Hope that helps.

2
  • Thanks t31os! Of course it was that. The problem was that submit function was interacting with every Form in the website. But it's strange that it was working before.
    – UXTE
    Feb 17, 2011 at 15:45
  • Happy to have helped. With regard to that running on every form, if that's not what you need, couldn't you simply update the selector to point at specific forms, say those with a class? eg. $('form.someclass').submit( function(){ ...
    – t31os
    Feb 17, 2011 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.