News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Correct way to add a required registration field?

Started by Glyph, September 26, 2016, 04:55:51 AM

Previous topic - Next topic

Glyph

Question:
What i'm trying to do is add a new input field to the registration page that is required. I'm trying to avoid using custom profile fields because then an administrator could accidentally edit it or something; just bad practice imo, so i'de just like to make this a static requirement. What is the correct way of doing this?

Research:
$sourcesdir/Register.php there is an array:
// Set the options needed for registration.
$regOptions = array(
'interface' => 'guest',
'username' => !empty($_POST['user']) ? $_POST['user'] : '',
'email' => !empty($_POST['email']) ? $_POST['email'] : '',
'password' => !empty($_POST['passwrd1']) ? $_POST['passwrd1'] : '',
'password_check' => !empty($_POST['passwrd2']) ? $_POST['passwrd2'] : '',
'openid' => !empty($_POST['openid_identifier']) ? $_POST['openid_identifier'] : '',
'auth_method' => !empty($_POST['authenticate']) ? $_POST['authenticate'] : '',
'check_reserved_name' => true,
'check_password_strength' => true,
'check_email_ban' => true,
'send_welcome_email' => !empty($modSettings['send_welcomeEmail']),
'require' => !empty($modSettings['coppaAge']) && !$verifiedOpenID && empty($_SESSION['skip_coppa']) ? 'coppa' : (empty($modSettings['registration_method']) ? 'nothing' : ($modSettings['registration_method'] == 1 ? 'activation' : 'approval')),
'extra_register_vars' => array(),
'theme_vars' => array(),
);


What I would like to do is add this to the array: 'apikey' => !empty($_POST['apikey']) ? $_POST['apikey'] : '',

Hypothesis:
Would I be correct in assuming i'll need to add an input field to Register.template.php directly? Is there a function or hook that will do this for me? (other than custom_profile_fields) also for the POST request handling, that will need to be manual too correct? Inside of the "Register2" function?
Personal TODO:

Suki

Yes, thats pretty much how you would do it on 2.0  There isn't a hook for it although 2.1 has some improvements for it.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: