MyBB Community Forums
Creating a new input under registration page? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Creating a new input under registration page? (/thread-200096.html)



Creating a new input under registration page? - ViLeGlyph - 2016-09-07

Please bear with me! i'm completely new to mybb plugin development and I am creating a plugin that will add extra options to the member registration page. I'm wondering if there is a built in way to create an input field in mybb. I will also be adding extra columns to the users table in mysql - if you know of any predefined functions for this i'de be very happy.

for example i would like to add another input to be used like on line 160 of /member.php


"apikey" => $mybb->get_input('apikey'),


Now as far as i can tell there's alot of predefined fuinctions in mybb and i'm wondering _where_ the input fields are being generated in html.

From what I can tell the structure is to use /inc/functions_users.php so I figured there would maybe be something like class_register.php or something along those lines. Thanks for your time and I appreciate all and any pointers.


RE: Creating a new input under registration page? - DiegoPino - 2016-09-07

Quote:I am creating a plugin that will add extra options to the member registration page.

Maybe can help you Do it from Administration Control Panel:

 - ACP, Home » Security Questions Here you can create and manage security questions that will be randomly shown during registration

For Example in ACP
[Image: Captura_de_pantalla_2016_09_07_a_las_12_18_26_a.png]

And the Registration Page Display:

[Image: Captura_de_pantalla_2016_09_07_a_las_12_17_46_a.png]


RE: Creating a new input under registration page? - ViLeGlyph - 2016-09-07

This would work great however i'm trying to create a plugin that will add the option. But this is a good point in the right direction.

https://community.mybb.com/archive/index.php?thread-112195.html

describes my same issue on exception of the hook - i will be using it on the register page.

only thing i can think of at this point is some jquery trickery with the hook "member_register_start"

I figure that it has something to do with mybb's template system and the plugin library settings which I know nothing about.

I'm going absolutely mad trying to figure out why this isn't working!



<?php

// Make sure we can't access this file directly from the browser.
if(!defined('IN_MYBB'))
{
die('This file cannot be accessed directly.');
}

// cache templates - this is important when it comes to performance
// THIS_SCRIPT is defined by some of the MyBB scripts, including members.php
if(THIS_SCRIPT == 'members.php'){
global $templatelist;
if(isset($templatelist)){
$templatelist .= ',';
}
$templatelist .= 'testapikey';
}


/**
* Standard functions
*/
function testAPI_info(){
   global $lang;

   $lang->load("testAPI");
   $lang->testAPIDesc = 'Integrates the test API to your board' . $lang->testAPIDesc;

   return Array(
       'name' => 'testAPI',
       'description' => 'Integrates the test API to your board',
       'website' => '',
       'author' => 'Glyph',
       'authorsite' => '',
       'version' => '0.1',
       'guid' => '',
       'compatibility' => '18*',
       'codename' => 'testAPI'
   );
}

/**
* Plugin Class
*/
class testAPI
{
   /**
    * start plugin hooks
    */
   public function __construct(){
       global $plugins;
//$plugins->add_hook("admin_config_profile_fields_add", "fieldsonpostbit_add");
$plugins->add_hook("member_register_start", "testAPI_register");

   }
}

function testAPI_activate(){
global $db;

$query = $db->simple_select("settinggroups", "gid", "name='member'");
$gid = $db->fetch_field($query, "gid");
// Insert settings
$insertarray = array(
'name' => 'apikeyrequired',
'title' => 'Require test API Key',
'description' => 'If you wish to make the API Key field required, set this option to yes.',
'optionscode' => 'yesno',
'value' => 0,
'disporder' => 39,
'gid' => (int)$gid
);
$db->insert_query("settings", $insertarray);

rebuild_settings();
// Add a new template to our global templates (sid = -1)
$insert_array = array(
'title' => 'testapikey',
'template' => $db->escape_string('<br />
<fieldset class="trow2">
<legend><strong>WHOA</strong></legend>
<table cellspacing="0" cellpadding="{$theme[\'tablespace\']}">
<tr>
<td colspan="2"><span class="smalltext">test</span></td>
</tr>
<tr>
<td colspan="2">
inpout goes here
</td>
</tr>
</table>
</fieldset>'),
'sid' => '-1',
'version' => '',
'dateline' => TIME_NOW
);
$db->insert_query("templates", $insert_array);

include MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("member_register", "#".preg_quote('{$requiredfields}')."#i", '{$testkeys}{$requiredfields}');

}

function testAPI_register(){
global $mybb, $db, $templates, $testkeys;
$blankoption = '';

eval("\$testkeys .= \"".$templates->get("testapikey")."\";");
exit;
}

// This function runs when the plugin is deactivated.
function testAPI_deactivate(){
global $db;
// remove our template
include MYBB_ROOT."/inc/adminfunctions_templates.php";
$db->delete_query('templates', 'title IN (\'testAPI_register\') AND sid=\'-1\'');
rebuild_settings();
find_replace_templatesets("member_register", "#".preg_quote('{$testkeys}')."#i", '', 0);

}

function testAPI_install(){

}


function testAPI_uninstall(){

}


If this worked the way i wanted it to it would add this to my registration page upon activation:
<br />
<fieldset class="trow2">
<legend><strong>WHOA</strong></legend>
<table cellspacing="0" cellpadding="{$theme[\'tablespace\']}">
<tr>
<td colspan="2"><span class="smalltext">test</span></td>
</tr>
<tr>
<td colspan="2">
inpout goes here
</td>
</tr>
</table>
</fieldset>



RE: Creating a new input under registration page? - Profit - 2016-09-11

Try this:

function testAPI_register(){
global $mybb, $db, $templates, $testkeys;
$blankoption = '';

$testkeys = '<br />

<fieldset class="trow2">

<legend><strong>WHOA</strong></legend>

<table cellspacing="0" cellpadding="{$theme[\'tablespace\']}">

<tr>

<td colspan="2"><span class="smalltext">test</span></td>

</tr>

<tr>

<td colspan="2">

inpout goes here

</td>

</tr>

</table>
</fieldset>';
}



RE: Creating a new input under registration page? - dragonexpert - 2016-09-11

I would try the datahandler_user_insert and datahandler_user_insert_end. https://docs.mybb.com/1.8/development/plugins/hooks/