Add UCP Module for Custom Profile Fields

Discussion forum for MOD Writers regarding MOD Development.
User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Add UCP Module for Custom Profile Fields

Post by Volksdevil » Tue Jan 07, 2014 3:47 pm

Solved
Read from here viewtopic.php?f=71&t=2220591#p13564406 to see how to achieve this. Read carefully all the way to the end of page 3 and you will get this working. Thanks to John for the help. :)

-----------------------------------------------

I'd like to add a new module, (a very simple one which would basically be based on the UCP > PROFILE > EDIT PROFILE. Where all the things like 'Website, Occupation' etc are.

The tab should be at the top after
Overview | Profile | Board preferences | Private messages | Usergroups | Friends & Foes

But I'd like it to only contain custom profile fields. (I already add them to the profile pages individually)
I looked at adding a module but I'm getting lost on what I need to do, I have searched and found unanswered topics, and instructions that seem to be way over my head/too complicated for what I need.

I thought I could basically copy the template file > ucp_profile_profile_info.html but rename it to ucp_profile_car_info.html and then remove all the standard profile fields and just leaving my custom profile fields. Does that sound plausible?

If so, I don't know where to go from there?

Any help appreciated.
Last edited by Volksdevil on Thu Mar 06, 2014 5:13 pm, edited 3 times in total.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51868
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Brf » Tue Jan 07, 2014 7:04 pm


User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Tue Jan 07, 2014 8:18 pm

Cheers Brf, I saw similar links but I'm not sure they will completely aid me in doing what I'd like. But I've followed the details of that link and also https://wiki.phpbb.com/Creating_modules and nothing seems to show up or work regards the module. :cry:

I changed any instance of ACP and acp to UCP and ucp etc.

I have:
includes/ucp/info/ucp_profile_corrado.php

Code: Select all

<?php
class ucp_profile_corrado_info
{
    function module()
    {
        return array(
            'filename'    => 'ucp_profile_corrado',
            'title'        => 'UCP_PROFILE_CORRADO',
            'version'    => '1.2.3',
            'modes'        => array(
                'index'        => array('title' => 'UCP_PROFILE_CORRADO_INDEX_TITLE', 'auth' => 'acl_a_profile_corrado_auth', 'cat' => array('')),
            ),
        );
    }

    function install()
    {
    }

    function uninstall()
    {
    }
}
?>
includes/ucp/ucp_profile_corrado.php

Code: Select all

<?php
class ucp_profile_corrado
{
   var $u_action;
   var $new_config;
   function main($id, $mode)
   {
      global $db, $user, $auth, $template;
      global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
      switch($mode)
      {
         case 'index':
            $this->page_title = 'UCP_PROFILE_CORRADO';
            $this->tpl_name = 'ucp_profile_corrado';
            break;
      }

   }
}
?>
template folder/ucp_profile_corrado.html

Code: Select all

<!-- INCLUDE overall_header.html -->

Hello, World!

<!-- INCLUDE overall_footer.html -->
language/en/mods/info_ucp_profile_corrado.php

Code: Select all

<?php
/**
* DO NOT CHANGE
*/
if (empty($lang) || !is_array($lang))
{
    $lang = array();
}
// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

$lang = array_merge($lang, array(
    'UCP_PROFILE_CORRADO_INDEX_TITLE'                        => 'Corrado Title',
));
?>
EDIT: AAAAAAAAAAAAARH! I'm completely confused! :cry: I just basically want to copy the 'Profile' tab but with the standard info removed and the custom profile fields kept.

EDIT2: Just spent ages copying each of the profile php and template files, then renaming them by adding 'corrado' on the end and renaming instances of profile inside each one with 'profilecorrado'

Have got a tab showing in UCP, but it's loading text with no profile fields...

Tried and failed! Why is it so damn hard? :cry:
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Sun Feb 23, 2014 10:32 pm

Bump. :) I can't believe how much I'm struggling with this :evil:

I've actually got the module showing up, but it's showing basically everything from the ucp_profile_profile_info file which I've copied and renamed.

Here is my file includes/ucp/ucp_corrado.php How can I remove all profile data but show specific custom profile fields such as: (YEAR, PRODUCTION, STYLE, COLOUR) Those are the names of the custom profile fields in the database that I wish to show.

Code: Select all

<?php
/**
*
* @package ucp
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* ucp_corrado
* Changing profile settings
*
* @todo what about pertaining user_sig_options?
* @package ucp
*/
class ucp_corrado
{
	var $u_action;

	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;

		$user->add_lang('posting');

		$preview	= (!empty($_POST['preview'])) ? true : false;
		$submit		= (!empty($_POST['submit'])) ? true : false;
		$delete		= (!empty($_POST['delete'])) ? true : false;
		$error = $data = array();
		$s_hidden_fields = '';

		switch ($mode)
		{

			case 'corrado_info':

				include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);

				$cp = new custom_profile();

				$cp_data = $cp_error = array();

				$data = array(
					'icq'			=> request_var('icq', $user->data['user_icq']),
					'aim'			=> request_var('aim', $user->data['user_aim']),
					'msn'			=> request_var('msn', $user->data['user_msnm']),
					'yim'			=> request_var('yim', $user->data['user_yim']),
					'jabber'		=> utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)),
					'year'		=> request_var('year', $user->data['user_website']),
					'location'		=> utf8_normalize_nfc(request_var('location', $user->data['user_from'], true)),
					'occupation'	=> utf8_normalize_nfc(request_var('occupation', $user->data['user_occ'], true)),
					'interests'		=> utf8_normalize_nfc(request_var('interests', $user->data['user_interests'], true)),
				);

				if ($config['allow_birthdays'])
				{
					$data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;

					if ($user->data['user_birthday'])
					{
						list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']);
					}

					$data['bday_day'] = request_var('bday_day', $data['bday_day']);
					$data['bday_month'] = request_var('bday_month', $data['bday_month']);
					$data['bday_year'] = request_var('bday_year', $data['bday_year']);
					$data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
				}

				add_form_key('ucp_corrado_info');

				if ($submit)
				{
					$validate_array = array(
						'icq'			=> array(
							array('string', true, 3, 15),
							array('match', true, '#^[0-9]+$#i')),
						'aim'			=> array('string', true, 3, 255),
						'msn'			=> array('string', true, 5, 255),
						'jabber'		=> array(
							array('string', true, 5, 255),
							array('jabber')),
						'yim'			=> array('string', true, 5, 255),
						'website'		=> array(
							array('string', true, 12, 255),
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
						'location'		=> array('string', true, 2, 100),
						'occupation'	=> array('string', true, 2, 500),
						'interests'		=> array('string', true, 2, 500),
					);

					if ($config['allow_birthdays'])
					{
						$validate_array = array_merge($validate_array, array(
							'bday_day'		=> array('num', true, 1, 31),
							'bday_month'	=> array('num', true, 1, 12),
							'bday_year'		=> array('num', true, 1901, gmdate('Y', time()) + 50),
							'user_birthday' => array('date', true),
						));
					}

					$error = validate_data($data, $validate_array);

					// validate custom profile fields
					$cp->submit_cp_field('profile', $user->get_iso_lang_id(), $cp_data, $cp_error);

					if (sizeof($cp_error))
					{
						$error = array_merge($error, $cp_error);
					}

					if (!check_form_key('ucp_corrado_info'))
					{
						$error[] = 'FORM_INVALID';
					}

					if (!sizeof($error))
					{
						$data['notify'] = $user->data['user_notify_type'];

						if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml')))
						{
							// User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled)
							// Disable notify by Jabber now for this user.
							$data['notify'] = NOTIFY_EMAIL;
						}

						$sql_ary = array(
							'user_icq'		=> $data['icq'],
							'user_aim'		=> $data['aim'],
							'user_msnm'		=> $data['msn'],
							'user_yim'		=> $data['yim'],
							'user_jabber'	=> $data['jabber'],
							'user_website'	=> $data['website'],
							'user_from'		=> $data['location'],
							'user_occ'		=> $data['occupation'],
							'user_interests'=> $data['interests'],
							'user_notify_type'	=> $data['notify'],
						);

						if ($config['allow_birthdays'])
						{
							$sql_ary['user_birthday'] = $data['user_birthday'];
						}

						$sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user->data['user_id'];
						$db->sql_query($sql);

						// Update Custom Fields
						$cp->update_profile_field_data($user->data['user_id'], $cp_data);

						meta_refresh(3, $this->u_action);
						$message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
						trigger_error($message);
					}

					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}

				if ($config['allow_birthdays'])
				{
					$s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = 1; $i < 32; $i++)
					{
						$selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
						$s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
					}

					$s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = 1; $i < 13; $i++)
					{
						$selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
						$s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
					}
					$s_birthday_year_options = '';

					$now = getdate();
					$s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
					{
						$selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
						$s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
					}
					unset($now);

					$template->assign_vars(array(
						'S_BIRTHDAY_DAY_OPTIONS'	=> $s_birthday_day_options,
						'S_BIRTHDAY_MONTH_OPTIONS'	=> $s_birthday_month_options,
						'S_BIRTHDAY_YEAR_OPTIONS'	=> $s_birthday_year_options,
						'S_BIRTHDAYS_ENABLED'		=> true,
					));
				}

				$template->assign_vars(array(
					'ERROR'		=> (sizeof($error)) ? implode('<br />', $error) : '',

					'ICQ'		=> $data['icq'],
					'YIM'		=> $data['yim'],
					'AIM'		=> $data['aim'],
					'MSN'		=> $data['msn'],
					'JABBER'	=> $data['jabber'],
					'WEBSITE'	=> $data['website'],
					'LOCATION'	=> $data['location'],
					'OCCUPATION'=> $data['occupation'],
					'INTERESTS'	=> $data['interests'],
				));

				// Get additional profile fields and assign them to the template block var 'profile_fields'
				$user->get_profile_fields($user->data['user_id']);

				$cp->generate_profile_fields('profile', $user->get_iso_lang_id());

			break;
		}

		$template->assign_vars(array(
			'L_TITLE'	=> $user->lang['UCP_CORRADO_' . strtoupper($mode)],

			'S_HIDDEN_FIELDS'	=> $s_hidden_fields,
			'S_UCP_ACTION'		=> $this->u_action)
		);

		// Set desired template
		$this->tpl_name = 'ucp_corrado_' . $mode;
		$this->page_title = 'UCP_CORRADO_' . strtoupper($mode);
	}
}

?>
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Tue Feb 25, 2014 1:15 am

Can anyone help at all? :)
Volksdevil wrote:Bump. :) I can't believe how much I'm struggling with this :evil:

I've actually got the module showing up, but it's showing basically everything from the ucp_profile_profile_info file which I've copied and renamed.

Here is my file includes/ucp/ucp_corrado.php How can I remove all profile data but show specific custom profile fields such as: (YEAR, PRODUCTION, STYLE, COLOUR) Those are the names of the custom profile fields in the database that I wish to show.

Code: Select all

<?php
/**
*
* @package ucp
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* ucp_corrado
* Changing profile settings
*
* @todo what about pertaining user_sig_options?
* @package ucp
*/
class ucp_corrado
{
	var $u_action;

	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;

		$user->add_lang('posting');

		$preview	= (!empty($_POST['preview'])) ? true : false;
		$submit		= (!empty($_POST['submit'])) ? true : false;
		$delete		= (!empty($_POST['delete'])) ? true : false;
		$error = $data = array();
		$s_hidden_fields = '';

		switch ($mode)
		{

			case 'corrado_info':

				include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);

				$cp = new custom_profile();

				$cp_data = $cp_error = array();

				$data = array(
					'icq'			=> request_var('icq', $user->data['user_icq']),
					'aim'			=> request_var('aim', $user->data['user_aim']),
					'msn'			=> request_var('msn', $user->data['user_msnm']),
					'yim'			=> request_var('yim', $user->data['user_yim']),
					'jabber'		=> utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)),
					'year'		=> request_var('year', $user->data['user_website']),
					'location'		=> utf8_normalize_nfc(request_var('location', $user->data['user_from'], true)),
					'occupation'	=> utf8_normalize_nfc(request_var('occupation', $user->data['user_occ'], true)),
					'interests'		=> utf8_normalize_nfc(request_var('interests', $user->data['user_interests'], true)),
				);

				if ($config['allow_birthdays'])
				{
					$data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;

					if ($user->data['user_birthday'])
					{
						list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']);
					}

					$data['bday_day'] = request_var('bday_day', $data['bday_day']);
					$data['bday_month'] = request_var('bday_month', $data['bday_month']);
					$data['bday_year'] = request_var('bday_year', $data['bday_year']);
					$data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
				}

				add_form_key('ucp_corrado_info');

				if ($submit)
				{
					$validate_array = array(
						'icq'			=> array(
							array('string', true, 3, 15),
							array('match', true, '#^[0-9]+$#i')),
						'aim'			=> array('string', true, 3, 255),
						'msn'			=> array('string', true, 5, 255),
						'jabber'		=> array(
							array('string', true, 5, 255),
							array('jabber')),
						'yim'			=> array('string', true, 5, 255),
						'website'		=> array(
							array('string', true, 12, 255),
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
						'location'		=> array('string', true, 2, 100),
						'occupation'	=> array('string', true, 2, 500),
						'interests'		=> array('string', true, 2, 500),
					);

					if ($config['allow_birthdays'])
					{
						$validate_array = array_merge($validate_array, array(
							'bday_day'		=> array('num', true, 1, 31),
							'bday_month'	=> array('num', true, 1, 12),
							'bday_year'		=> array('num', true, 1901, gmdate('Y', time()) + 50),
							'user_birthday' => array('date', true),
						));
					}

					$error = validate_data($data, $validate_array);

					// validate custom profile fields
					$cp->submit_cp_field('profile', $user->get_iso_lang_id(), $cp_data, $cp_error);

					if (sizeof($cp_error))
					{
						$error = array_merge($error, $cp_error);
					}

					if (!check_form_key('ucp_corrado_info'))
					{
						$error[] = 'FORM_INVALID';
					}

					if (!sizeof($error))
					{
						$data['notify'] = $user->data['user_notify_type'];

						if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml')))
						{
							// User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled)
							// Disable notify by Jabber now for this user.
							$data['notify'] = NOTIFY_EMAIL;
						}

						$sql_ary = array(
							'user_icq'		=> $data['icq'],
							'user_aim'		=> $data['aim'],
							'user_msnm'		=> $data['msn'],
							'user_yim'		=> $data['yim'],
							'user_jabber'	=> $data['jabber'],
							'user_website'	=> $data['website'],
							'user_from'		=> $data['location'],
							'user_occ'		=> $data['occupation'],
							'user_interests'=> $data['interests'],
							'user_notify_type'	=> $data['notify'],
						);

						if ($config['allow_birthdays'])
						{
							$sql_ary['user_birthday'] = $data['user_birthday'];
						}

						$sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user->data['user_id'];
						$db->sql_query($sql);

						// Update Custom Fields
						$cp->update_profile_field_data($user->data['user_id'], $cp_data);

						meta_refresh(3, $this->u_action);
						$message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
						trigger_error($message);
					}

					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}

				if ($config['allow_birthdays'])
				{
					$s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = 1; $i < 32; $i++)
					{
						$selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
						$s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
					}

					$s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = 1; $i < 13; $i++)
					{
						$selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
						$s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
					}
					$s_birthday_year_options = '';

					$now = getdate();
					$s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
					for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
					{
						$selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
						$s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
					}
					unset($now);

					$template->assign_vars(array(
						'S_BIRTHDAY_DAY_OPTIONS'	=> $s_birthday_day_options,
						'S_BIRTHDAY_MONTH_OPTIONS'	=> $s_birthday_month_options,
						'S_BIRTHDAY_YEAR_OPTIONS'	=> $s_birthday_year_options,
						'S_BIRTHDAYS_ENABLED'		=> true,
					));
				}

				$template->assign_vars(array(
					'ERROR'		=> (sizeof($error)) ? implode('<br />', $error) : '',

					'ICQ'		=> $data['icq'],
					'YIM'		=> $data['yim'],
					'AIM'		=> $data['aim'],
					'MSN'		=> $data['msn'],
					'JABBER'	=> $data['jabber'],
					'WEBSITE'	=> $data['website'],
					'LOCATION'	=> $data['location'],
					'OCCUPATION'=> $data['occupation'],
					'INTERESTS'	=> $data['interests'],
				));

				// Get additional profile fields and assign them to the template block var 'profile_fields'
				$user->get_profile_fields($user->data['user_id']);

				$cp->generate_profile_fields('profile', $user->get_iso_lang_id());

			break;
		}

		$template->assign_vars(array(
			'L_TITLE'	=> $user->lang['UCP_CORRADO_' . strtoupper($mode)],

			'S_HIDDEN_FIELDS'	=> $s_hidden_fields,
			'S_UCP_ACTION'		=> $this->u_action)
		);

		// Set desired template
		$this->tpl_name = 'ucp_corrado_' . $mode;
		$this->page_title = 'UCP_CORRADO_' . strtoupper($mode);
	}
}

?>
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Wed Feb 26, 2014 2:54 am

Bump for the above.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Wed Feb 26, 2014 7:33 am

Only show or also editable?
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Wed Feb 26, 2014 2:02 pm

Hi John, thanks for the reply...

I'd like to show specific individual custom profile fields via includes/ucp/ucp_corrado.php without any other core fields. And of course the custom profile fields are already set up and editable via my HTML in the new UCP module that I've set up so that should be ok?

I'm just struggling to remove all the core phpbb fields from includes/ucp/ucp_corrado.php and add individual custom profile fields.

The actual fields I wish to show are called: YEAR, PRODUCTION, STYLE, COLOUR in the database.

--------------------------
Here is the html file which my custom profile fields are listed in, as you can see I use if statements to grab them like <!-- BEGIN profile_fields --><!-- IF profile_fields.FIELD_ID eq "pf_year" -->

Code: Select all

<!-- INCLUDE ucp_header.html -->

<script type="text/javascript" src="highslide/highslide-with-gallery.js"></script>
<script type="text/javascript" src="highslide/highslide.config.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />

<form id="ucp" method="post" action="{S_UCP_ACTION}"{S_FORM_ENCTYPE}>

<h2>{L_TITLE}</h2>

<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>
	<p>{L_PROFILE_INFO_NOTICE}</p>

	<fieldset>
	<!-- IF ERROR --><p class="error">{ERROR}</p><!-- ENDIF -->

<h3>Corrado G60 Details</h3>
<p>These details should reflect the Corrado G60 that you currently use on the road, or off the road if it's your only project/vehicle. <a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here</a> to find <span class="blue"><strong>Year of Manufacture</strong></span> / <span class="green"><strong>Production Number</strong></span></p>

<!-- BEGIN profile_fields -->
<!-- IF profile_fields.FIELD_ID eq "pf_year" -->
<dl>

<!-- <div class="highslide-gallery" style="display:none">
	<ul>
	<li>
<a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" onclick="return hs.expand(this, config1 )">
<img src="http://www.corradog60.com/images/corrado_g60_vin_decode_thumb.png" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture"></a>
	</li>
	</ul>
</div> -->
<dt><label<!-- IF profile_fields.FIELD_ID --> for="{profile_fields.FIELD_ID}"<!-- ENDIF -->>{profile_fields.LANG_NAME}:
<!-- IF profile_fields.S_REQUIRED --> *<!-- ENDIF --></label>
<!-- IF profile_fields.LANG_EXPLAIN --><br /><span>{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF --></dt>
<!-- IF profile_fields.ERROR --><dd class="error">{profile_fields.ERROR}</dd><!-- ENDIF -->
<dd>{profile_fields.FIELD}<!-- &nbsp;<a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here to find Year of Manufacture</a> -->
</dd>
</dl>
<!-- ENDIF -->



















<!-- IF profile_fields.FIELD_ID eq "pf_year_b" -->
<dl>
<dt><label<!-- IF profile_fields.FIELD_ID --> for="{profile_fields.FIELD_ID}"<!-- ENDIF -->>{profile_fields.LANG_NAME}:
<!-- IF profile_fields.S_REQUIRED --> *<!-- ENDIF --></label>
<!-- IF profile_fields.LANG_EXPLAIN --><br /><span>{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF --></dt>
<!-- IF profile_fields.ERROR --><dd class="error">{profile_fields.ERROR}</dd><!-- ENDIF -->
<dd>{profile_fields.FIELD}<!-- &nbsp;<a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here to find Year of Manufacture</a> -->
</dd>
</dl>
<!-- ENDIF -->





























<!-- IF profile_fields.FIELD_ID eq "pf_production" -->
<dl>
<dt><label<!-- IF profile_fields.FIELD_ID --> for="{profile_fields.FIELD_ID}"<!-- ENDIF -->>{profile_fields.LANG_NAME}:
<!-- IF profile_fields.S_REQUIRED --> *<!-- ENDIF --></label>
<!-- IF profile_fields.LANG_EXPLAIN --><br /><span>{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF --></dt>
<!-- IF profile_fields.ERROR --><dd class="error">{profile_fields.ERROR}</dd><!-- ENDIF -->
<dd>{profile_fields.FIELD}</dd></dl><dl>&nbsp;</dl>
<!-- ENDIF -->

<!-- IF profile_fields.FIELD_ID eq "pf_style" -->
<dl>
<dt><label<!-- IF profile_fields.FIELD_ID --> for="{profile_fields.FIELD_ID}"<!-- ENDIF -->>{profile_fields.LANG_NAME}:
<!-- IF profile_fields.S_REQUIRED --> *<!-- ENDIF --></label>
<!-- IF profile_fields.LANG_EXPLAIN --><br /><span>{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF --></dt>
<!-- IF profile_fields.ERROR --><dd class="error">{profile_fields.ERROR}</dd><!-- ENDIF -->
<dd>{profile_fields.FIELD}</dd></dl><dl>&nbsp;</dl>
<!-- ENDIF -->

<!-- IF profile_fields.FIELD_ID eq "pf_colour" -->
<dl>
<dt><label<!-- IF profile_fields.FIELD_ID --> for="{profile_fields.FIELD_ID}"<!-- ENDIF -->>{profile_fields.LANG_NAME}:
<!-- IF profile_fields.S_REQUIRED --> *<!-- ENDIF --></label>
<!-- IF profile_fields.LANG_EXPLAIN --><br /><span>{profile_fields.LANG_EXPLAIN}</span><!-- ENDIF --></dt>
<!-- IF profile_fields.ERROR --><dd class="error">{profile_fields.ERROR}</dd><!-- ENDIF -->
<dd>{profile_fields.FIELD}</dd></dl>
<dl><strong>Click <a href="http://www.corradog60.com/images/corrado_g60_boot_sticker.png" style="width: 100px; height:66px;" alt="Corrado G60 | Colour Code Sticker" title="Corrado G60 | Colour Code Sticker" class="highslide" onclick="return hs.expand(this, config1 )">HERE</a> to find <span class="red">Colour Code</span> using sticker found on rear panel within boot/trunk.</strong></dl>
<!-- ENDIF -->
<!-- END profile_fields -->

	</fieldset>

	<span class="corners-bottom"><span></span></span></div>
</div>

<fieldset class="submit-buttons">
	{S_HIDDEN_FIELDS}<input type="reset" value="{L_RESET}" name="reset" class="button2" />&nbsp; 
	<input type="submit" name="submit" value="{L_SUBMIT}" class="button1" />
	{S_FORM_TOKEN}
</fieldset>
</form>

<!-- INCLUDE ucp_footer.html -->
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Wed Feb 26, 2014 2:51 pm

So the fields are editable and are the other fields you don't want to show required?
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Wed Feb 26, 2014 3:26 pm

Hi John, do you mean required as in 'Must be filled in'? or required as in 'Do I need/want' to include them?

I've just made an image to help explain too.
Image
Image hosted by neepic
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Wed Feb 26, 2014 4:33 pm

Yes must be filled in.
For example, a user looks in your ucp module and wants to save it but he has never filled in other fields in cp that are required.

What should happen then, because the cp record isn't there and it should be saved now without the other fields?
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Wed Feb 26, 2014 4:54 pm

Hi John, thankyou for the help on this.

Ok, I think I understand, Yes, it should be saved without the other fields (That I don't want to show/be in the php/html) because those other fields are 'Required upon registration' so they will already have been taken care of?

Each of the fields marked in green are 'Required' upon registration and ucp changes, they are:
Real First Name. (Custom field)
Location. (Custom field)
Country. (Custom field)
Gender. (Custom field)
Birthday (Core field but modded to be a required field)


Image
Image hosted by neepic

But of course I don't want any of those fields in my new UCP tab/module.

------------------------------------------

Edit: Here you go John, a test login so that you can see what I've done so far and what I'm trying to achieve

http://www.corradog60.com
REMOVED LOGIN DETAILS

If you navigate between the core '[REMOVED LINK]' tab and my new '[REMOVED LINK]' tab you can see how I've basically copied my profile fields under the <H3> heading Corrado G60 Details from the core profile tab to my new 'Corrado G60 Register' tab.

But you will see the issue if you hit 'Submit' when viewing the tab [REMOVED LINK] that the unwanted fields are still within the php.

If this can actually be done I'm sure it will help a lot!!! of other people too. 8-) I've found lots of topics asking for a specific custom profile field tab, but no end results.
Last edited by Volksdevil on Mon Jan 12, 2015 3:42 pm, edited 4 times in total.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by Volksdevil » Wed Feb 26, 2014 5:15 pm

Please delete! Replied instead of edited. :oops:
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Wed Feb 26, 2014 7:19 pm

Ok give me a little time.
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

User avatar
John P
Registered User
Posts: 1237
Joined: Mon Jan 21, 2008 3:55 pm
Location: Netherlands
Name: John
Contact:

Re: Add UCP Module for Custom Profile Fields

Post by John P » Wed Feb 26, 2014 8:43 pm

Ok here my tryouts,

File ucp_profile_corrado.php in info folder

Code: Select all

<?php
/**
*
* @package ucp
* @version $Id: ucp_profile_corrado.php 2014-02-26 22:0:00Z Forumhulp.com $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @package module_install
*/
class ucp_profile_corrado_info
{
    function module()
    {
        return array(
            'filename'    => 'ucp_profile_corrado',
            'title'        => 'UCP_PROFILE_CORRADO',
            'version'    => '1.0.0',
            'modes'     => array(
                'indfo'    => array('title' => 'UCP_PROFILE_CORRADO', 'auth' => '', 'cat' => array('UCP_MAIN')),
            ),
        );
    }

    function install()
    {
    }

    function uninstall()
    {
    }
}
?>
File ucp_profile_corrado.php in ucp folder

Code: Select all

<?php
/**
*
* @package ucp
* @version $Id: ucp_profile_corrado.php 2014-02-26 22:0:00Z Forumhulp.com $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @package module_install
*/
if (!defined('IN_PHPBB'))
{
   exit;
}

class ucp_profile_corrado
{
    var $u_action;

    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;

        $submit = (isset($_POST['submit'])) ? true : false;
        if ($submit)
        {
            $sql_ary = array(
                'pf_year'       => request_var('year', 1900),
                'pf_production'    => request_var('production', ''),
                'pf_style'        => request_var('style', 0),
                'pf_colour'     => request_var('colour', 0));

            $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' 
                    SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
                    WHERE user_id = ' . $user->data['user_id'];
            $db->sql_query($sql);
        }
        
        $sql = 'SELECT pf_year, pf_production, pf_style, pf_colour FROM ' . PROFILE_FIELDS_DATA_TABLE . ' WHERE user_id = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        
        $selectyear = '';
        for ($i = 1900; $i < 2014; $i++)
        {
            $selected = ($row['pf_year'] == $i) ? ' selected="selected"': '';
            $selectyear .= '<option value="' . $i . '"' . $selected. '>' . $i . '</option>'; 
        }
        
        $selectstyle = '';
        $stylearay = array(0 => 'Early style', 1 => 'Late style');
        foreach ($stylearay as $key => $value)
        {
            $selected = ($row['pf_style'] == $key) ? ' selected="selected"': '';
            $selectstyle .= '<option value="' . $key . '"' . $selected. '>' . $value . '</option>'; 
        }
        
        $colourstyle = '';
        $colouraray = array(0 => 'Black', 1 => 'Blue', 3 => 'White', 4 => 'Red');
        foreach ($colouraray as $key => $value)
        {
            $selected = ($row['pf_colour'] == $key) ? ' selected="selected"': '';
            $colourstyle .= '<option value="' . $key . '"' . $selected. '>' . $value . '</option>'; 
        }
        
        $template->assign_vars(array(
            'YEAR'             => $selectyear,
            'PRODUCTION'     => $row['pf_production'],
            'STYLE'            => $selectstyle,
            'COLOUR'        => $colourstyle
            )
        );    
    
    
        // Set desired template
        $this->tpl_name = 'ucp_corrado';
        $this->page_title = 'UCP_CORRADO_' . strtoupper($mode);
    }
}
template ucp_corrado.html

Code: Select all

<!-- INCLUDE ucp_header.html -->

<script type="text/javascript" src="highslide/highslide-with-gallery.js"></script>
<script type="text/javascript" src="highslide/highslide.config.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />

<form id="ucp" method="post" action="{S_UCP_ACTION}"{S_FORM_ENCTYPE}>

<h2>{L_TITLE}</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>
   <p>{L_PROFILE_INFO_NOTICE}</p>

   <fieldset>
   <!-- IF ERROR --><p class="error">{ERROR}</p><!-- ENDIF -->

<h3>Corrado G60 Details</h3>
<p>These details should reflect the Corrado G60 that you currently use on the road, or off the road if it's your only project/vehicle. <a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here</a> to find <span class="blue"><strong>Year of Manufacture</strong></span> / <span class="green"><strong>Production Number</strong></span></p>

<dl>
<dt><label for="year">Year:</label>
<br /><span>Year explain</span></dt>
<dd><select id="year" name="year">{YEAR}</select><!-- &nbsp;<a href="http://www.corradog60.com/images/corrado_g60_vin_decode.png" class="highslide" style="width: 100px; height:66px;" alt="Corrado G60 | Year of Manufacture" title="Corrado G60 | Year of Manufacture" onclick="return hs.expand(this, config1 )">Click Here to find Year of Manufacture</a> -->
</dd>
</dl>

<dl>
<dt><label for="production">Production:</label>
<br /><span>Production explain</span></dt>
<dd><input id="production" name="production" value="{PRODUCTION}" /></dd>
</dl>

<dl>
<dt><label for="style">Style:</label>
<br /><span>Style explain</span></dt>
<dd><select id="style" name="style">{STYLE}</select></dd>
</dl>

<dl>
<dt><label for="colour">Colour:</label>
<br /><span>Colour explain</span></dt>
<dd><select id="colour" name="colour">{COLOUR}</select></dd>
</dl>

<dl><strong>Click <a href="http://www.corradog60.com/images/corrado_g60_boot_sticker.png" style="width: 100px; height:66px;" alt="Corrado G60 | Colour Code Sticker" title="Corrado G60 | Colour Code Sticker" class="highslide" onclick="return hs.expand(this, config1 )">HERE</a> to find <span class="red">Colour Code</span> using sticker found on rear panel within boot/trunk.</strong></dl>

   </fieldset>

   <span class="corners-bottom"><span></span></span></div>
</div>

<fieldset class="submit-buttons">
   {S_HIDDEN_FIELDS}<input type="reset" value="{L_RESET}" name="reset" class="button2" />&nbsp; 
   <input type="submit" name="submit" value="{L_SUBMIT}" class="button1" />
   {S_FORM_TOKEN}
</fieldset>
</form>

<!-- INCLUDE ucp_footer.html -->
Language variabele not yet included
Image
Webhosting, Custom MODs, Technical management, MOD installation and Webdesign

Locked

Return to “[3.0.x] MOD Writers Discussion”