vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Setting custom userfields (https://vborg.vbsupport.ru/showthread.php?t=262441)

squishi 04-22-2011 09:45 AM

Setting custom userfields
 
I am in the process of creating an additional registration step to my forum.
I want to set custom userfields in the register_start hook.

Here is what I have:
PHP Code:

//some code

    
$vbulletin->input->clean_array_gpc('r', array(
        
'userfield' => TYPE_ARRAY,
    ));

    
$userdata =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);

    
// set profile fields
    
$customfields $userdata->set_userfields($vbulletin->GPC['userfield'], true'normal');

//some more code 


My problem is that vb checks for required fields. I've tried using the set_userfields method with 'admin', 'normal' or 'register', but the result is the same.

So how do I set custom fields with regex verification (for security) but without checking if fields are required?

kh99 04-22-2011 01:43 PM

So I'm assuming that the problem is that you only want the regex errors in the error array? Maybe something like:

PHP Code:

//some code 

   
function filter_field_errors($params)
   {
       if (
$params[1] == 'required_field_x_missing_or_invalid')
           
array_pop({$params[0]}->errors);
   }

    
$vbulletin->input->clean_array_gpc('r', array( 
        
'userfield' => TYPE_ARRAY
    )); 

    
$userdata =& datamanager_init('User'$vbulletinERRTYPE_ARRAY); 
    
$userdata->set_failure_callback('filter_field_errors');

    
// set profile fields 
    
$customfields $userdata->set_userfields($vbulletin->GPC['userfield'], true'normal'); 

//some more code 


(BTW I haven't tried this at all, even to check for typos).

squishi 04-22-2011 06:15 PM

I did not know about the possibility of a callback.
Just a minute ago, I found the solution to my problem and came here to report back.
I found it in profile.php.

PHP Code:

    $userdata->set_existing($vbulletin->userinfo); 

Needs to be added after the userdata object is initialized.
That way, I do not run into missing username etc. errors.


All times are GMT. The time now is 09:08 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.01701 seconds
  • Memory Usage 1,723KB
  • 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
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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