vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 2.x Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=4)
-   -   Numeric Required User Profile Field (https://vborg.vbsupport.ru/showthread.php?t=35118)

Logician 02-15-2002 10:00 PM

Hey there,

I have a "graduation year" and an extra "birthyear" (admin view only) user profile fields in my board, so I wrote this hack to make sure members are entering valid and acceptable numeric data for these fields. ;)

This hack will require your members to enter a numeric data (numbers) for a user profile field. If the user did not enter a number or if the number is not between the limits you set, he will get an error message and should go back and enter a valid number.

INSTALLATION

1- Login to your CP and create a new template named:
"error_numericfieldonly"

In your template specify your error message. eg:
-- cut --
You should enter number between X and B for the field A. Please go back and correct it.
-- cut --

2- In "User Profiles", create your profile field (should be a "required" field). After you create it, click "Modify User Profile Field". Find your field in the list, left mouse click on "EDIT" link and choose "Open in New Window". In the new window check your browser's address bar: at the end you'll see smt. like that "profilefieldid=5". This is your field's ID. Note that number.

3- Edit "register.php" and "member.php". Find this:
PHP Code:

    // ENTER ANY CUSTOM FIELD VALIDATION HERE!
    //Make sure user didn't try to bypass the maxchars for the fields 

Right after that ADD:

PHP Code:

// Logician Numeric Required User Profile Hack
// REMEMBER to substitute correct number in $fieldX below!
  
$log_field=(float) $fieldX;
// Line below will round decimal numbers. If you let your users enter decimals, simply put // at the beginning of the line below
  
$log_field=round($log_field); 
// Substitute 1920 and 1990 with your min.-max. limits.
    
if ($log_field 1920 OR $log_field >1990 
        {eval(
"standarderror(\"".gettemplate("error_numericfieldonly")."\");"); exit;}
// REMEMBER to substitute correct number in $fieldX below!
    
$fieldX=(string) $log_field;
// Logician Numeric Required User Profile Hack 

That's it.. Upload your files to your server. From now on, when a user registers or edits his profile, your board will check if he entered a valid numeric value for the field you set and will not let him register/change his profile unless he enters a valid number for this field. This restriction does not apply to you if you use Admin CP to change user fields. ;) Remember to recheck/edit field ID, if you add/remove/modify user profile fields in your CP.

Enjoy! \\=^))
Logician

TheComputerGuy 02-16-2002 06:58 PM

Sweet great hack, I like it

Ruth 02-18-2002 08:56 PM

great hack, i requested such hack long time ago specifically for a graduation year, plus it would be nice to have a count down for each member to the graduation year ;)

Jawelin 05-14-2002 01:14 PM

Excuse me.
Great idea and nice small hack.

Actually, with che code you suggested, such a check for one field would be performed each custom field for the same X number (it's within the while clause).
I think should be better to replace the above code with something like :
PHP Code:

    //HACK: Numeric Required Field in User Profile
    
if ($profilefield[profilefieldid]==X) {   // number of field you're checking
      
if (is_numeric($$varname)) {
        
$log_field=round((float)$$varname);
      } else {
        
$log_field=0;
      }
      if (
$log_field 1920 OR $log_field 1990 ) {
        eval(
"standarderror(\"".gettemplate("error_numericfieldonly")."\");");
        exit;
      }
      $
$varname=(string)$log_field;
    }
    
//HACK: Numeric Required Field in User Profile 

The problem rises mostly when you have required fields. If the above field it isn't numeric, the above exception comes before the required field one. This way I realized such a mis-function.... :p

Thanks again and sorry the intrusion.
But I did this way and would share such a small work-around.
Bye

Logician 05-14-2002 02:35 PM

@javelin: Honestly it's not a big deal for me which error user gets first : required field error or numeric entry error. But your code is a good enhancement for Admins who care, so thanks for sharing.. :)

Regards,
Logician \\=^))

Jawelin 05-14-2002 02:52 PM

Of course. Nothing to say: your hack works and it's a nice idea (this reason I installed it too) :D....
And when installed I found such a small problem; tried to fix it and though someone else could have the same...

Thanks again.
Bye

KingsGambit 12-01-2002 10:39 PM

Great idea for a great hack. Our of curiosity, would it be possible to modify this to work for a *post* field. eg. Have an extra field in the newthread and newreply that requires numeric entry for the post to be accepted?

Logician 12-01-2002 10:58 PM

Quote:

Originally posted by KingsGambit
Great idea for a great hack. Our of curiosity, would it be possible to modify this to work for a *post* field. eg. Have an extra field in the newthread and newreply that requires numeric entry for the post to be accepted?
clarify please.. Also posting your recent code that requires the hack will help..


All times are GMT. The time now is 09:57 PM.

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.00971 seconds
  • Memory Usage 1,745KB
  • 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)bbcode_quote_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