Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

function to allow the option of no text in comment textarea WordPress

  • SOLVED

I want users the option to not include any text in the comment textarea, but they can if they like.

[[LINK href="https://developer.wordpress.org/reference/functions/wp_handle_comment_submission/"]]https://developer.wordpress.org/reference/functions/wp_handle_comment_submission/[[/LINK]]
[[LINK href="http://wordpress.stackexchange.com/questions/206418/how-to-allow-duplicate-comments-and-without-comment-text"]]http://wordpress.stackexchange.com/questions/206418/how-to-allow-duplicate-comments-and-without-comment-text
[[/LINK]]

Rather than no text I am happy with some hidden text

Answers (2)

2016-01-22

Reigel Gallarde answers:

Can you include the purpose? and what do you mean by "some hidden text" ?


Reigel Gallarde comments:

Currently, there's no way to add this ability using WordPress codes.

After investigating, I have a suggestion or solution.

First we'll have to remove the required attribute of the textarea. After that, when submitting, check if value of textarea is empty. If empty, change the value to '%dummy-text%'. Then change the '%dummy-text%' text on display.

something like this.

function rei_preprocess_comment($comment_data) {

if ($comment_data['comment_content'] == '%dummy-text%') {
$comment_data['comment_content'] = ''; // replace dummy text.
}

return $comment_data;
}
add_filter('preprocess_comment', 'rei_preprocess_comment');

function rei_wp_footer() {
?>
<script>
jQuery(function($){
var comment = $('textarea#comment');
comment.removeAttr('required'); // remove required attribute of textarea.
$('#commentform').on('submit',function(){
if (comment.val() == '') {
comment.css('text-indent','-999px').val('%dummy-text%'); // change to dummy text.
}
});

});
</script>
<?php
}
add_action( 'wp_footer', 'rei_wp_footer' );


pjeaje comments:

<blockquote>Can you include the purpose?</blockquote>
I'm using a comment field plugin and only want that pulgin's comment field data outputted

<blockquote>what do you mean by "some hidden text" ?</blockquote>
I mean there could be the option to include a defined text that could satisfy the requirement to include text but then hide it so t can't be seen.


pjeaje comments:

Your above function works.


Reigel Gallarde comments:

ok.. try my solution

2016-01-22

Darlene Grace Arcenal answers:

If there's no text on the comment textarea, your comment box has no purpose then.


pjeaje comments:

<blockquote>If there's no text on the comment textarea, your comment box has no purpose then.</blockquote>

Yes there is. One such case is the need to allow users to acknowledge a post by clicking the comment submit but the post author does not want any text submitted. There's lots of other cases.