Version: 1.00, by Logician
Developer Last Online: Nov 2023
Version: 2.2.x
Rating:
Released: 02-15-2002
Last Update: Never
Installs: 9
No support by the author.
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
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
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
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....
Thanks again and sorry the intrusion.
But I did this way and would share such a small work-around.
Bye
@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..
Of course. Nothing to say: your hack works and it's a nice idea (this reason I installed it too) ....
And when installed I found such a small problem; tried to fix it and though someone else could have the same...
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?
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..