PDA

View Full Version : Way to force "I agree" checkbox before posting in specific forums?


tastyratz
04-26-2011, 01:05 PM
Hello,
We are having issues with user compliance with rules of "forgetting" them.

I would like to force a checkbox for our marketplace section where users have to agree they are an interested party only.

I want this ONLY in the marketplace forum, and I want it persistent against all posts in the section.

Is there a plugin/hack out there which could cleanly fit my needs on a 3.8 install?

kh99
04-26-2011, 02:59 PM
I'm not sure what you mean by "persistent against all posts" - do you mean you just want them to answer once, or each time they post?

If it's the first one I don't know, maybe there's a mod out there. If it's the second one, you could create a plugin using hook newpost_process and something like this code:


if (in_array($foruminfo['forumid'], array(1, 2, 3)))
{
$vbulletin->input->clean_gpc('p', 'accept_rules', TYPE_BOOL);

if (!$vbulletin->GPC['accept_rules'])
{
$errors[] = "You must accept the rules before posting";
}
}



then in the appropriate templets (showthread, newreply, and newthread I think), add something like this:


<if condition="in_array($foruminfo['forumid'], array(1, 2, 3))">
<tr>
<td><input type="checkbox" class="bginput" name="accept_rules" value="true"/> I accept the forum rules</td>
</tr>
</if>



(You don't have to make it a table row of course.)

You also want to change the 1, 2, 3 in each case to the forum number or numbers you want this to apply to.

You could also make a javascript popup to check before it's submitted if you like that idea better.

RedTurtle
11-03-2012, 08:34 AM
Would this work on vB4?

kh99
11-03-2012, 09:25 AM
I think it should, but you'd have to update the "if" tags in the template like this:

<vb:if condition="in_array($foruminfo['forumid'], array(1, 2, 3))">
<tr>
<td><input type="checkbox" class="bginput" name="accept_rules" value="true"/> I accept the forum rules</td>
</tr>
</vb:if>

CoffeeLovesYou
11-03-2012, 08:15 PM
kh99,

We have a forum that has cursing in it and can have serious conversations.. How can I use your plugin to make it so when they click on the forum, it gives them the same checkbox, and if they press I agree, it shows them the forum and all of the threads/posts and what not. Kind of like how if you go to a certain website, it may say "Content not suitable for children".. well, I want it to be kind of like a warning "This area of the forum has language that may not be suitable for children and serious conversations. Leave now and go back to the main forum if not interested. Agree if you'd like to proceed into the forum." something like that.

Thank you!

kh99
11-03-2012, 10:12 PM
That's more complicated. It's fairly easy to do for posting because there's already a mechanism for checking for errors and going to the "go advanced" page if there are any, and it's a one-time thing. To do what you want you'd have to create your own way to decide if the user had accepted or not (because you don't want them to have to click for every page). You should spend some time searching for something like this if you haven't already. If you want to create it, you might look at how forum passwords work because it's a similar idea. Or maybe you can figure out a way to use the forum password mechanism, like make the password "agree" then change the forum password message to say "if you accept enter 'agree'".

RedTurtle
11-04-2012, 12:06 AM
I think it should, but you'd have to update the "if" tags in the template like this:

<vb:if condition="in_array($foruminfo['forumid'], array(1, 2, 3))">
<tr>
<td><input type="checkbox" class="bginput" name="accept_rules" value="true"/> I accept the forum rules</td>
</tr>
</vb:if>

Thanks again for being so helpful kh99 :)

I have created and enabled the plugin as you suggested above and am now putting the following in my SHOWTHREAD template, right above the code for the signature checkbox:

<vb:if condition="in_array($foruminfo['forumid'], array(3, 4, 17, 24))">
<tr>
<td><input type="checkbox" class="bginput" name="accept_rules" value="true"/>I agree to follow the rules.</td>
</tr>
</vb:if>

I checked that both the plugin and this template code have the same forum IDs in the code but for some reason it doesn't appear on the SHOWTHREAD page.

Any idea what I could be doing wrong? Thank you!

kh99
11-04-2012, 12:59 AM
You're using vb4, right? (Edit: of course, you just mentioned it above). Try this instead (change foruminfo to threadinfo):

<vb:if condition="in_array($threadinfo['forumid'], array(3, 4, 17, 24))">
<tr>
<td><input type="checkbox" class="bginput" name="accept_rules" value="true"/>I agree to follow the rules.</td>
</tr>
</vb:if>

RedTurtle
11-04-2012, 01:03 AM
Hi Kh99,

So I am having an issue with the plugin.

I'm using the following code:

if ($GLOBALS['forumid'] != 99 AND is_member_of($bbuserinfo, 5,6,7))
{
$vbulletin->input->clean_gpc('p', 'accept_rules', TYPE_BOOL);

if (!$vbulletin->GPC['accept_rules'])
{
$errors[] = "<span style='color: #ba0000; background-color: #FDFD65;'>Please scroll down and accept the highlighted rules before submitting your post.</span>";
}
}

Because I want it to show in all forums (put the 99 in there to make it work) and I want it to only apply to usergroups 5,6,7 (admin, mod, super mod).

Now if I use is_member_of($bbuserinfo, 5,6,7) it doesn't seem to work. If I put an exclamation in front of it then it works...but I'm not sure why...

EDIT: So here's the following things I've tried, as an admin:

if ($GLOBALS['forumid'] !=99 AND is_member_of($bbuserinfo, 5,6,7)) <== Doesn't work (lets me post)
if ($GLOBALS['forumid'] !=99 AND is_member_of($bbuserinfo, 2,3,4)) <== Works (lets me post)
if ($GLOBALS['forumid'] !=99 AND !is_member_of($bbuserinfo, 5,6,7)) <=== Doesn't let me as an admin post (so it works, but not sure why it needs an ! in front of is_member_of)

kh99
11-04-2012, 09:02 AM
You can only use $bbuserinfo in a template condition. If you want to check in a plugin, use $vbulletin->userinfo. Also, if you want it to work for all forums you can just take out the forum check (unless you're leaving it there for future use or something). So try:
if (is_member_of($vbulletin->userinfo, 5,6,7))
{


I guess in the other thread I assumed when you asked for a conditional you meant a template condition.

BTW, ! just means "not", so it was working only because the check was always failing (so !is_member_of was always true), but I think you would have found that it was true for all members.

RedTurtle
11-04-2012, 03:17 PM
You're extremely helpful. Thank you again.

I did get it working. I did have one more question however.

If I am specifying a lot of different usergroups in my template and plugin and don't want to have to individually go back and change each template anytime I make a change in my usergroups, is there a way I can define an array in place of the usergroups?

Something like: <vb:if condition="in_array($GLOBAL['forumid'], $MyUsergroups)"> ?

How would I create a plugin that would then feed $MyUsergroups to the templates?

Thank you again.

kh99
11-04-2012, 03:27 PM
What you could do in that case is set a variable in the plugin to true, then in the template condition just check the variable. In fact you could use the $show[] array that exists already, as long as you choose a name that you're sure would be unique.

For example, in the plugin you could do something like:

$MyUsergroups = array(1, 3, 5, 57);
if (is_member_of($bbuserinfo, $MyUsergroups))
{
...some code..
$show['some_unique_name'] = true;
... more code
}


then in the template

<vb:if condition="$show['some_unique_name']">
// show something
</vb:if>

RedTurtle
11-04-2012, 03:41 PM
My Plugin Code:

//This plugin controls users accepting the rules on each post until they are promoted to Registered Users Plus.
//Template edits for this plugin have been made in SHOWTHREAD, NEWREPLY, and NEWTHREAD
//A custom phrase called spelling_checkbox was added

$SpellingUsergroups = array(2, 3, 4, 6);
if (is_member_of($vbulletin->userinfo, $SpellingUsergroups))
{
$show['spelling_checker'] = true;

$vbulletin->input->clean_gpc('p', 'accept_rules', TYPE_BOOL);


if (!$vbulletin->GPC['accept_rules'])
{
$errors[] = "<span style='color: #ba0000; background-color: #FDFD65;'>Please scroll down and accept the highlighted rules before submitting your post.</span>";
}
}

My Template Code:

<vb:if condition="$show['spelling_checker']">
<div class="spelling_checkbox">
<ul class="checkradio">
<li><label for="rules">
<input type="checkbox" id="rules" class="bginput" name="accept_rules" value="true"/>
{vb:rawphrase spelling_checkbox}
</label></li>
</ul>
</div>
</vb:if>

It doesn't show up however on the page.


Am I making a mistake by putting the $SpellingUsergroups = array(2, 3, 4, 6); and $show['spelling_checker'] = true; in the same plugin as the other code? Does it need to be in a different plugin at a different hook location? Right now all of this is at newpost_process...

--------------- Added 1352047913 at 1352047913 ---------------

Ok I added a new plugin, using this example of yours:

$MyUsergroups = array(1, 3, 5, 57);
if (is_member_of($bbuserinfo, $MyUsergroups))
{
...some code..
$show['some_unique_name'] = true;
... more code
}

but used $vbulletin->userinfo instead of $bbuserinfo and put it to work at parse_templates. Seems to be working...going to test some more though :)

kh99
11-04-2012, 03:54 PM
You say the plugin is using newpost_process but your template change is in SHOWTHREAD? That's probably the problem because newpost_process isn't called before SHOWTHREAD.

RedTurtle
11-04-2012, 04:00 PM
Thanks again.

I have 2 plugins now and then 3 template edits (in showthread, newreply, and newthread)

My first plugin which is called at parsetemplates:

$SpellingUsergroups = array(6, 7);
if (is_member_of($vbulletin->userinfo, $SpellingUsergroups))
{
$show['spelling_checker'] = true;
}


My second plugin which is called at newpost_process

//This plugin controls users accepting the rules on each post until they are promoted to Registered Users Plus.
//Template edits for this plugin have been made in SHOWTHREAD, NEWREPLY, and NEWTHREAD
//A custom phrase called spelling_checkbox was added

if (is_member_of($vbulletin->userinfo, $SpellingUsergroups))
{
$vbulletin->input->clean_gpc('p', 'accept_rules', TYPE_BOOL);


if (!$vbulletin->GPC['accept_rules'])
{
$errors[] = "<span style='color: #ba0000; background-color: #FDFD65;'>Please scroll down and accept the highlighted rules before submitting your post.</span>";
}
}


And my template edit:

<vb:if condition="$show['spelling_checker']">
<div class="spelling_checkbox">
<ul class="checkradio">
<li><label for="rules">
<input type="checkbox" id="rules" class="bginput" name="accept_rules" value="true"/>
{vb:rawphrase spelling_checkbox}
</label></li>
</ul>
</div>
</vb:if>


Now the plugin that works at parse_templates is working properly. It will show the template edits to the proper usergroup and the checkbox shows up.

However if I see the checkbox and try to make a post without clicking on the checkbox, it still allows it...making me think the plugin at newpost_process is not correctly getting the $SpellingUsergroups definition that is being defined in the plugin at parsetemplates.

Thanks for sticking with me through this -- I am learning quite a bit but am still hitting a few speed bumps. Thank you.

kh99
11-04-2012, 04:03 PM
Yeah, I think the problem is that the newpost_process hook is being called before parse_templates. If that's all the code you have in your parse_templates plugin, try moving it to global_setup_complete (or whatever it's called - I can never remember).

RedTurtle
11-04-2012, 04:06 PM
Tried it at global_setup_complete and global_bootstrap_init_start and neither seem to work.

kh99
11-04-2012, 04:23 PM
Oh yeah...try it again, but add "global $vbulletin, $show;" at the beginning.

RedTurtle
11-04-2012, 04:31 PM
Ok it still allows me to post without having the checkbox selected.

Here's how I have it now:
global $vbulletin, $show;
$SpellingUsergroups = array(6, 67);
if (is_member_of($vbulletin->userinfo, $SpellingUsergroups))
{
$show['spelling_checker'] = true;
}

at global_setup_complete

kh99
11-04-2012, 04:44 PM
OK, try changing the newpost_process plugin to:

global $show;
if ($show['spelling_checker'])
{

RedTurtle
11-04-2012, 04:49 PM
That did it! :)

Interestingly enough the other plugin works only if its at global_setup_complete instead of parse_templates.

Good to know.

Thank you so much kh99! You're always so patient with me. :)

CoffeeLovesYou
11-08-2012, 12:04 PM
kh99,
Thank you for the suggestion. I modified the forum password phrase to be a warning message and have them type in 'agree' in the password box to enter the forum. However, this way currently works, but if I want to set up a warning message for a different forum, how could I do that, then? In the current warning message, I have the warning + the rules of the area, if I set a password for another forum, then they will see the warning message that is only supposed to be for that certain forum. Thanks.

kh99
11-08-2012, 01:11 PM
Hmm...you could try this: create a plugin using hook error_fetch and code something like:

if (!is_array($args[0]) AND $args[0] == 'forumpasswordmissing' AND !$vbulletin->GPC['ajax'])
{
global $forumid;
switch ($forumid)
{
case 1:
case 2:
$args[0] = 'forumrules_1_2';
break;
case 3:
$args[0] = 'forumrules_3';
break;
// etc
}
}


Then create the new phrases you need (by copying the original forumpasswordmissing and editing it).