Jump to content

Make Registration Invite Only using a passcode


sol2010

Recommended Posts

Hi all and especially @brian!

I've searched the threads and can't find anyone else with the same request... though similar ones exit here and also here

I am looking for a  way to do this - put simply: have a code on the registration page that a user has to fill out before they can register (similar to a passcode)

That way, registration will be by Invite Only and prevents all the scammers who sign up (we don't offer mass services)

I am guessing the "Invitation Code" box could be added fine as a custom field ?  But how to check that the entry is valid - ideally via Ajax prior to form submission?  (e.g. against a passcode I have set up in the backend.?)

If anyone has successfully achieved that, please advise!

Thanks for help

Link to comment
Share on other sites

11 hours ago, sol2010 said:

I am guessing the "Invitation Code" box could be added fine as a custom field ? 

yes.

11 hours ago, sol2010 said:

But how to check that the entry is valid - ideally via Ajax prior to form submission?  (e.g. against a passcode I have set up in the backend.?)

if you wanted to do this without any coding (e.g hook), then I would put the validation within the custom field as regex...

T2JvEO6.png

that would add the field to the registration page (and also checkout in the cart), and unless the invite code is entered correctly, e.g 'brian' (case sensitive - so 'Brian' woudn't be valid). an error message will be shown.

2yFdidu.png

if you wanted to allow multiple different invite codes to be valid, then you can add a list of valid options to the regex..

/^(tom|dick|harry)$/

or if you wanted to make it case-insensitive, e.g so haRrY would be valid, then it would be...

/^(tom|dick|harry)$/i

... though you probably shouldn't need to use that as you likely want what is entered to be exact as the valid code(s).

I think there is only one downside to this solution - but that would only apply if this "Invite Code" custom field was added after existing clients had already registered - they would be unable to edit their profile because the IC field wouldn't have been set for them, but it's required and they won't know what the valid code is/are.... the hook below should fix by injecting the code into the field if it doesn't exist - additionally, it converts the text field to a password to hide the code (though it could be viewed from the browser source code if they want to).

<?php

# Inject Invite Code Into Client Profiles Hook
# Written by brian!

function client_profiles_invite_code_hook($vars) {
	
	$customfields = $vars['customfields'];
	$invitefield = "Invite Code";
	$invitecode = "123456789012345";
	foreach ($customfields as $key => $field) {
		if ($field['name'] == $invitefield && empty($field['value'])) {
			$customfields[$key]['input'] = str_replace("text","password",$field['input']);
			$customfields[$key]['input'] = str_replace('value=""','value="'.$invitecode.'"',$customfields[$key]['input']);
		}
	}
	return array("customfields" => $customfields);
}
add_hook("ClientAreaPageProfile", 1, "client_profiles_invite_code_hook");

the only two lines you should need to change is the $invitefield and $invitecode variables - the first is the name of your custom field; the second is a valid invite code value.

there could be a further issue if you changed the invite code after a user had registered - because they would have an existing value that had become invalid and would then be unable to edit their profile.... that's fixable though, as would be pulling the valid values from the database if you really had to - but i'm trying to keep this simple for now until you get your head around how this might work.

Link to comment
Share on other sites

You beauty @brian!

Registration page code works a treat (after a bit of customising.)

One query so far: how can I check in the hook, if a client is active (I don't want this invite code showing in any inactive client accounts?)

Thank you @brian! I would love to buy you a beer or coffee so do tell me how that is feasible.

 

Link to comment
Share on other sites

14 hours ago, sol2010 said:

Registration page code works a treat (after a bit of customising.)

you meant the invite code is no longer "brian" 🤪

14 hours ago, sol2010 said:

One query so far: how can I check in the hook, if a client is active (I don't want this invite code showing in any inactive client accounts?)

you would just need two more lines of code and to wrap the function if a conditional if statement...

<?php

# Inject Invite Code Into Client Profiles Hook
# Written by brian!

function client_profiles_invite_code_hook($vars) {
	
	$client = Menu::context('client');
	$status = $client->status;
	if ($status == "Active") {
		$customfields = $vars['customfields'];
		$invitefield = "Invite Code";
		$invitecode = "123456789012345";
		foreach ($customfields as $key => $field) {
			if ($field['name'] == $invitefield && empty($field['value'])) {
				$customfields[$key]['input'] = str_replace("text","password",$field['input']);
				$customfields[$key]['input'] = str_replace('value=""','value="'.$invitecode.'"',$customfields[$key]['input']);
			}
		}
		return array("customfields" => $customfields);
	}
}
add_hook("ClientAreaPageProfile", 1, "client_profiles_invite_code_hook");
Link to comment
Share on other sites

17 hours ago, sol2010 said:

Thank you once again @brian!, very helpful. 

I'm not sure where you are located, but in any case, I'm sending you some virtual sunshine, pizza and surf, to be consumed in any order, though perhaps not at the same time  😉

😎🌞🏄‍♂️🍕

send umbrella or canoe - the rain won't stop! 🛶

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated