We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
  • Pages:
  • 1
Flexible Form Script Extension: Restrict Groups
Topic Started: Jul 7 2012, 05:46 PM (1,870 Views)
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Code Name: Flexible Form Script Extension: Restrict Groups

What the code does: This code works with Reid's Flexible Form Script and will allow you to restrict user groups from sending in applications.

How to use the code: Change Group ID as necessary. The Group ID can be retrieved via the page source (look for 'gid'), or via the member list by selecting a group from the 'Displaying' drop down menu, the &group= number found in the address bar is the Group ID.

How to install the code:

Below the Flexible Form Script code:
Code:
 
<script type="text/javascript">
//<![CDATA[
function dGroup(groupID) {
var group = $.zb.stat.gid;

if (group == groupID) {
form_script.form_id.html('<table cellspacing="0" id="error_box"><thead><tr><th>Error:</th></tr></thead><tbody><tr class="generic"><td>Your user group does not have permission to send in applications</td></tr></tbody></table>');
$('title').text('Error');
}
}

dGroup('GROUP_ID');
//]]>
</script>
Edited by Cory, Dec 13 2013, 12:02 AM.
Offline Profile Quote Post Goto Top
 
Nicolas-ZNR
Member Avatar
Member
[ *  *  *  *  *  *  * ]
Useful, but I do wonder why you did the AJAX request to find the name of the group and didn't just check $.zb.stat.gid (I know it requires admin to find the group IDs, but it's not that difficult and makes the code smoother).
Offline Profile Quote Post Goto Top
 
Geoffrey
Member Avatar
bury hatchets, keep maps
[ *  *  *  *  * ]
And we put in the group ID of the groups we want to exclude or include?
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
When you insert a Group ID it will disable the form from being used for that group.
Offline Profile Quote Post Goto Top
 
Ferby
Member Avatar
Developer
[ *  *  *  *  * ]
Kinda annoying because the restrict groups and required fields are compatible with each other
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
I'm not sure why that would be a bad thing, you can restrict groups only, require fields only, or restrict groups and require fields by using both codes.
Offline Profile Quote Post Goto Top
 
Geoffrey
Member Avatar
bury hatchets, keep maps
[ *  *  *  *  * ]
Cory
Jul 12 2012, 06:47 AM
I'm not sure why that would be a bad thing, you can restrict groups only, require fields only, or restrict groups and require fields by using both codes.
Ferby may have made a typo and meant to say they are not compatible.
Offline Profile Quote Post Goto Top
 
Ferby
Member Avatar
Developer
[ *  *  *  *  * ]
Geoffrey
Jul 12 2012, 10:16 AM
Cory
Jul 12 2012, 06:47 AM
I'm not sure why that would be a bad thing, you can restrict groups only, require fields only, or restrict groups and require fields by using both codes.
Ferby may have made a typo and meant to say they are not compatible.
yeah sorry. I tried both codes together and they didnt work
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
I just tested both codes together and they seemed to work for me. Mind posting your Flexible Form Script webpage content with the two codes added so I can see what the issue is?
Offline Profile Quote Post Goto Top
 
Ferby
Member Avatar
Developer
[ *  *  *  *  * ]
:doh: I thought the group you put in would be the only group able to submit a form. Read it wrong, sorry for being an idiot xDD

Could the OP edit the code so only certain groups can submit a application instead of restricting groups? Would be appreciated
Edited by Ferby, Jul 12 2012, 06:51 PM.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
Change === (in the first code) or == (in the second code) to != to make it so if the group name or group ID matches they can submit forms, instead of being restricted; basically doing the opposite of what it does now.
Offline Profile Quote Post Goto Top
 
Ferby
Member Avatar
Developer
[ *  *  *  *  * ]
Cory
Jul 13 2012, 07:16 AM
Change === (in the first code) or == (in the second code) to != to make it so if the group name or group ID matches they can submit forms, instead of being restricted; basically doing the opposite of what it does now.
works perfectly
Offline Profile Quote Post Goto Top
 
mawarm
Member
[ *  * ]
I changed the "==" to "!=", in order to define what groups are allowed to access the form, rather than what groups cannot access it, which seems to be working. However I can only get it working for one group; I'm not sure what the layout should be like when adding more groups, could you help me with this?
Also, I was wondering if it could be possible to have a separate error message for guests.
Offline Profile Quote Post Goto Top
 
Cory
Member Avatar
Member
[ *  *  *  *  *  *  *  *  * ]
You can repeat this line as many times as you like for additional user groups:
Code:
 
dGroup('GROUP_ID');
Use this for guests:
Code:
 
<script type="text/javascript">
//<![CDATA[
if ($.zb.logged_in === false) {
form_script.form_id.html('<table cellspacing="0" id="error_box"><thead><tr><th>Error:</th></tr></thead><tbody><tr class="generic"><td>Your user group does not have permission to send in applications</td></tr></tbody></table>');
$('title').text('Error');
}
//]]>
</script>
Offline Profile Quote Post Goto Top
 
mawarm
Member
[ *  * ]
I'm still not sure about the layout and can only get it working for one group at a time...when I try to add more groups it doesn't work for any group at all.
Please check out my code below and tell me what I'm doing wrong. It doesn't have anything to do with the separate error message for guests because I tried removing that part but it makes no difference.
Code:
 
<!-- Flexible Form Script -->
<form id='generic_form'>
<div class='category'>
<table class='cat_head'>
<tr>
<td><h2 style='text-align:center'>Application Form</h2></td>
</tr>
</table>
</div>

<table>
<tr>
<td> </td>
</tr>
</table>

<table id='form_spec'>
<tr>
<th colspan='2'><h2 style='text-align:center'>Please fill out the fields below.</h2></th>
</tr>
<tr>
<td>Steam Name:</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Steam ID (to find ID type ''Status'' into your console while in-game):</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Age:</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Time Zone:</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Where are you from?</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Do you have a mic, if not could you acquire one soon?</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Recruiter:</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>How long have you been playing Battle Grounds 2?</td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Are you proficient enough in English to communicate effectively with clan members?</td>
<td>
<select>
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td>About You:</td>
<td><textarea rows='3'></textarea></td>
</tr>
<tr>
<td>Why do you want to join the 29th Regiment?</td>
<td><textarea rows='3'></textarea></td>
</tr>
<tr>
<td colspan='2' style='text-align:center' id='send_form'><button type='submit'>Submit</button></td>
</tr>
</table>

</form>

<style type='text/css'>
/* <![CDATA[ */
#form_spec tr td:first-child {
font-weight: bold;
width: 30%;
}
#form_spec input, #form_spec textarea {
width: 500px;
}
/* ]]> */
</style>

<script type='text/javascript'>
var form_script = {
form_id: $('#generic_form'),
status_id: $('#send_form'),
specific_id: $('#form_spec'),
enable_guests: false,
pm: {
enabled: false, // Does not work for guests
user: "29thAdmin", // 1 user only
title: "Application - {{user_name}}",
content: "{{form}}"
},
topic: {
enabled: true,
forum_id: 5007385, // 1 id only
title: "Application - {{user_name}}",
description: "",
content: "{{form}}"
},
statuses: {
not_logged_in: "You must be registered and signed in to apply.", // Used if enable_guests: false
first: "Collecting data...",
second: "Sending application...",
done: "Application submitted!"
},
submission_formatting: {
separator: ' ',

before_all: '',
after_all: '',

before_question: '[b]',
after_question: '[/b]',

before_response: '[i]',
after_response: '[/i]'
},
possible_elements: 'input, textarea, select' // For the second column of table; .val() must work on it
};
</script>

<script type='text/javascript' src='http://z3.ifrm.com/313/104/0/p366373/form_script.js'></script>

<!-- Flexible Form Script Extension: Restrict Groups -->
<script type="text/javascript">
//<![CDATA[
function dGroup(groupID) {
var group = $.zb.stat.gid;

if (group != groupID) {
form_script.form_id.html('<table cellspacing="0" id="error_box"><thead><tr><th>Error:</th></tr></thead><tbody><tr class="generic"><td>Your user group does not have permission to send in applications.</td></tr></tbody></table>');
$('title').text('Error');
}
}

dGroup('3003425'); // Member
dGroup('3007969'); // Veteran
dGroup('3003422'); // Lord
dGroup('3007974'); // Admin
//]]>
</script>

<!-- Separate error message for guests -->
<script type="text/javascript">
//<![CDATA[
if ($.zb.logged_in === false) {
form_script.form_id.html('<table cellspacing="0" id="error_box"><thead><tr><th>Error:</th></tr></thead><tbody><tr class="generic"><td>You must be registered and signed in to apply.</td></tr></tbody></table>');
$('title').text('Error');
}
//]]>
</script>

<!-- Flexible Form Script Extension: Required Fields -->
<script type="text/javascript">
function rField(td_name) {
$('button').click(function (e) {
if ($('td:contains(' + td_name + ')').next().find('input, textarea').val().length === 0) {
e.returnValue = e.preventDefault && e.preventDefault() ? false : false;
alert("You must fill out the required fields.").one();
}
});
}

rField('Steam Name:');
rField('Steam ID (to find ID type ''Status'' into your console while in-game):');
rField('Age:');
rField('Time Zone:');
rField('Where are you from?');
rField('Do you have a mic, if not could you acquire one soon?');
rField('Why do you want to join the 29th Regiment?');
</script>
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · ZetaBoards Codes & Modifications · Next Topic »
Add Reply
  • Pages:
  • 1