Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am getting an error when the function below posts the form (from the second time, the first time it is blocked). When I click the submit button after this, the form submits without problem. The error is TypeError: e[h] is not a function. I already have changed the id of the submit button to something else than "submit".

The javascript:

jQuery(document).ready(function() {
    var submit_allowed = false;
    jQuery("#commentform").submit(function() {  
        var data = jQuery('#commentform').serialize()
        data +="&action=antispam_hook";
        jQuery.post(
            anti_spam_ajax.ajaxurl,
            data,
            function(data){
                submit_allowed = true;
                if (jQuery("#sg_anti_spam").length <= 0){
                    jQuery('#commentform').append('<input id="sg_anti_spam" type="hidden" name="sg_anti_spam" value="'+data+'" />');
                }
                jQuery('#commentform').submit();
            }
        );
        if (!submit_allowed) {
            return false;
        }
    });
});

The html:

<form action="http://xxxxxx/wp-comments-post.php" method="post" id="commentform">
<p class="comment-form-comment">
    <label for="comment">Reactie</label>
    <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
</p>
<p class="form-submit">
    <input name="submit" type="submit" id="submitform" value="Reactie plaatsen" />
    <input type='hidden' name='comment_post_ID' value='160984' id='comment_post_ID' />
    <input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</p>
</form>

Does anyone have an idea to fix this??

share|improve this question
    
You may want to read a little bit about jQuery and debugging. At least that's not a WordPress issue. –  kaiser Sep 12 '12 at 23:51
    
Oh yes, it is... Well, it is a jQuery issue that is triggered by how the default wordpress comment form is set up. –  jberculo Sep 18 '12 at 9:57
add comment

1 Answer

up vote 1 down vote accepted

I found the solution to my problem. When I searched for the answer I first encountered a solution which stated that it was a problem with the id of the form. I changed that by changing the id to something else:

comment_form(array('id_submit' => 'submitform'));

But that still didn't work. In the end it was because the name attribute was 'submit' also. The one problem is, that this attribute can not be changed like the id.

In the end I just made a small wrapper for the comment_form function, buffered the output and did a string replace:

/**
 * The following two functions are there to change the submit button name of the form. Otherwise jQuery dies.
 */
function sg_comment_form() {
        ob_start('sg_change_submit_name');
        comment_form(sg_get_comment_args());
        ob_end_flush();
}

function sg_change_submit_name($buffer) {
        return str_replace("name=\"submit","name=\"submit_sg",$buffer);
}

This fixed my problem.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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