vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Custom Profile Field - Add to 'Edit Email & Password' (modifypassword template) (https://vborg.vbsupport.ru/showthread.php?t=248994)

kharmer 08-20-2010 08:02 AM

Custom Profile Field - Add to 'Edit Email & Password' (modifypassword template)
 
Hi all,

How do I reference a Custom Profile Field in 'edit profile' type templates?

I need to add a custom field to the 'modifypassword' template; in other templates (i.e. signature area in postbit) I have referenced them like this:

PHP Code:

{vb:raw profile.field5

Thanks,
Kris...

--------------- Added [DATE]1282311891[/DATE] at [TIME]1282311891[/TIME] ---------------

The way I called custom profile fields in places like postbit templates is as indicated above.

So, how would I call the same custom profile fields from somewhere like the 'modifypassword' template?

Are custom profile fields actually in scope in these templates? And if not, how should I go about making them available (custom code in a hook!)?

Any pointers on this would be very much appreciated,
Kris...

Lynne 08-20-2010 02:25 PM

Do a search in your files for 'modifypassword' (with the single quotes) and you should find where it is rendered and you will also find which variables are registered for use in that template. Unfortunately, there are no variables registered for use in that template (take a look at it and you'll only see phrases and $show which doesn't need to be registered). So, if you want to use some variables in there, you will have to preregister them for use.

kharmer 08-23-2010 01:45 PM

Thanks for the pointer Lynne,

OK, so I have created a plugin in the 'global_bootstrap_init_start' hook.

This plugin contains the following 'test code' to preregister some dummy variables into the desired template.

PHP Code:

vB_Template::preRegister('modifypassword',array('myplugin_output' => 'ABCDEFG')); 

Using the following in the target template (modifypassword) works:

PHP Code:

{vb:raw myplugin_output

So, my next questions are ;o)

> How do I get the custom profile field values into my plugin? Do I have to run a database query? Or is there a smarter way?

> Should I be using the 'global_bootstrap_init_start' hook; I got it to work with the 'profile_editpassword_start' hook too?

> Should I use the 'global_bootstrap_init_start' hook and simply register all variables I'll need so I can implement them across multiple templates if needed?

> Should I just be registering these values in the individual templates where needed?

Thanks in advance for any pointers/advice,
Kris...

Lynne 08-23-2010 02:08 PM

Is this just the users/viewers fieldx? My guess is it may already have been queried and is available as variable $vbulletin->userinfo['fieldx'] . So, you could try using that.

You should only register a variable for use in the template you need to use it in.

kharmer 08-23-2010 02:29 PM

Yes, you're right. The user profile fields for the logged in user are already queried and your example works.

I now have in my plugin in the 'global_bootstrap_init_start' hook.

PHP Code:

## Create array of custom user profile fields
$customfields = array(
'ReferingHostName' => $vbulletin->userinfo['field5'],
'ReferingHostMemberCode' => $vbulletin->userinfo['field6']);

## preRegister variables for desired templates
# For 'modifypassword' template
vB_Template::preRegister('modifypassword',array('RTRvalues' => $customfields)); 


And I can refer to each of these like so (in the 'modifypassword' template).

PHP Code:

{vb:raw RTRvalues.ReferingHostName

PHP Code:

{vb:raw RTRvalues.ReferingHostMemberCode


With regards to the hook I amusing; should I use a more specific hook for 'modifypassword' template (if that was all I needed) so that it isnt invoked when not required? I was thinking of unnecessary overheads!

Thanks for your help Lynne, you're a star,
Kris...

Lynne 08-24-2010 03:15 AM

If you turn on debug mode (add "$config['Misc']['debug'] = true;" to the config.php file), then you will see a list of all the hook locations called on the page in order. You can try those hook locations and see if there is a better, more local, one.

kharmer 08-24-2010 08:22 AM

Thanks again Lynne; I've found a couple of hooks that are much more local/specific for the template I am preRegistering my custom variables for.

Kris...

mokonzi 09-06-2010 04:29 PM

Just looking at this thread, how would I be able to utilize the array as a conditional? i.e. check that what it contains equals something?

I'm trying to get a check done on a ProfileField entry, and then if it exists, do display or remove part of the template.

Any suggestions?


All times are GMT. The time now is 07:57 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01159 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete