MyBB Community Forums

Full Version: Require comments when giving negative reputation to posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello mybb friends:

Is there any way to require users to add comments when giving negative reputation to posts? There are some forum users registering to my prod forum not posting at all but would rather rate posts negatively. I know I could disable to rate negatively, but to make it fair, a forum user should be able to add positive and negative reputation to posts. However, to make it even fair to the user getting a negative repu, the user adding it should add a comment explaining why.
There is a way but it will force them to write a comment.
Could try this. Smile
https://community.mybb.com/thread-150751.html
(2018-10-16, 11:06 AM)Livewire Wrote: [ -> ]There is a way but it will force them to write a comment.
Could try this. Smile
https://community.mybb.com/thread-150751.html

Yes, that's the solution I'm looking for. However, that reputation.php version is not compatible with 1.8.18 (what I'm running), mine looks like this one:

	$mybb->input['comments'] = trim($mybb->get_input('comments')); // Trim whitespace to check for length
	if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'] && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)
	{
		$message = $lang->sprintf($lang->add_no_comment, $mybb->settings['minreplength']);
		if($mybb->input['nomodal'])
		{
			eval("\$error = \"".$templates->get("reputation_add_error_nomodal", 1, 0)."\";");
		}
		else
		{
			eval("\$error = \"".$templates->get("reputation_add_error", 1, 0)."\";");
		}
		echo $error;
		exit;

The base condition is not even there, so I'm still stuck. I would appreciate if you show me what needs to be tweaked.
BUMP

Hello comrades. I'm bumping this thread to see if somebody can give me a hand with this issue.

Thanks for all your support.
Well, the earlier guide posted by me which you have followed was for MyBB v1.6 and incompatible with v1.8.

You can validate the input right in frontend, by modifying 'submitReputation' method. Open 'general.js' and locate this code near line 365:
	submitReputation: function (uid, pid, del) {
		// Get form, serialize it and send it
		var datastring = $(".reputation_" + uid + "_" + pid).serialize();
		if (del == 1)
			datastring = datastring + '&delete=1';

		$.ajax({
			type: "POST",
			url: "reputation.php?modal=1",
			data: datastring,
			dataType: "html",
			success: function (data) {
				// Replace modal HTML (we have to access by class because the modals are appended to the end of the body, and when we get by class we get the last element of that class - which is what we want)
				$(".modal_" + uid + "_" + pid).fadeOut('slow', function () {
					$(".modal_" + uid + "_" + pid).html(data);
					$(".modal_" + uid + "_" + pid).fadeIn('slow');
					$(".modal").fadeIn('slow');
				});
			},
			error: function () {
				alert(lang.unknown_error);
			}
		});

		return false;
	},

Change it to:
	submitReputation: function (uid, pid, del) {
		if ($.trim($(".reputation_" + uid + "_" + pid + " input[name=comments]").val()) === '') {
			$.jGrowl('Please input Comment.', { theme: 'jgrowl_error' });
		} else {
			// Get form, serialize it and send it
			var datastring = $(".reputation_" + uid + "_" + pid).serialize();
			if (del == 1)
				datastring = datastring + '&delete=1';

			$.ajax({
				type: "POST",
				url: "reputation.php?modal=1",
				data: datastring,
				dataType: "html",
				success: function (data) {
					// Replace modal HTML (we have to access by class because the modals are appended to the end of the body, and when we get by class we get the last element of that class - which is what we want)
					$(".modal_" + uid + "_" + pid).fadeOut('slow', function () {
						$(".modal_" + uid + "_" + pid).html(data);
						$(".modal_" + uid + "_" + pid).fadeIn('slow');
						$(".modal").fadeIn('slow');
					});
				},
				error: function () {
					alert(lang.unknown_error);
				}
			});

		}

		return false;
	},

Now user will always be forced to add comment while giving reputation.

Note, that you need to validate in backend PHP as well, because disabling javascript will still allow users to add reputation without comments. And with v.1.8 its easy now, just omit the post reputation bypass condition from validation:

Open reputation.php and locate this line near line number 286:
if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'] && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)

and change it to:
if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'])// && $mybb->get_input('pid', MyBB::INPUT_INT) == 0)

or simply remove the last part, if you are sure:
if(my_strlen($mybb->input['comments']) < $mybb->settings['minreplength'])

Save the file.