4

I've been handed over a design to translate into WordPress plugin & theme. My question is regarding building a custom comment form.

The design used some custom scripts on the comment submit button. It handles 'submitting...' button state, animations, and checks. And it uses an anchor tag <a> with jQuery's .bind to submit the form.

I noticed that the comment_form function of WordPress did not offer a solution to change the submit button. I only needed to remove it as I'm handling it myself.

What made it worse is that WordPress has hard coded <input name="submit"> into the button, which made it impossible for jQuery to call .submit (more details on this issue here: https://stackoverflow.com/questions/12540953/property-submit-of-object-htmlformelement-is-not-a-function). So just hiding this button with CSS won't work.

If I prefer not to use the <input type="submit"> button of WordPress comment form, do I have any options to build my own button?

Thanks.

1

1 Answer 1

2

This is hard. Output buffering could solve that:

add_action( 'comment_form_field_comment', 'ob_start' );
add_action( 'comment_form', 'wpse_83898_replace_submit' );

function wpse_83898_replace_submit() 
{
    $html = ob_get_clean();
    # do some magic
    echo $html;
}

Just an idea, not tested.

1
  • Hi, thanks for the idea. I ended up hooking 'comment_form_before' and 'comment_form_after' altogether. And I used ob_start("hook_callback"); in 'before', and ob_end_flush() in 'after'. I then have a callback function to do whatever I want with the form.
    – He Shiming
    Commented Jan 31, 2013 at 11:32

Your Answer

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

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