1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom user field callback, validate value 1.x

For when you need special code to validate the value entered.

  1. Jake Bunce
    This is a skeleton for creating a callback for a custom user field. The callback is used to validate the value entered by the user. For example, if you are collecting some kind of ID that you need to check against another database.

    The callback is specified when editing the custom field:

    Screen shot 2012-01-12 at 10.51.04 PM.png

    The skeleton contains this file which matches the callback name:

    library/Callback/UserField.php

    The example code only accepts a value of '123'. Otherwise it defines an error message and returns false. It's a very simple example for demonstration. You can use your own code inside of the validate() function:

    Code:
    <?php
    
    class Callback_UserField
    {
    	public static function validate($field, &$value, &$error)
    	{
    		if ($value == '123')
    		{
    			return true;
    		}
    		else
    		{
    			$error = 'what no';
    			return false;
    		}
    	}
    }
    
    sbj, Marcus, SneakyDave and 6 others like this.

Recent Reviews

  1. Adam K M
    Adam K M
    5/5,
    Version: 1.x
    Thank you! This is just what I was looking for. Always great to see nifty tutorials like this one. Although I wish I could rate the resource without having to download it. (Since I'm only using my own class.)
  2. KamelJabber
    KamelJabber
    5/5,
    Version: 1.x
    Didn't know how to scrub profile details, followed this guide and it worked like a charm!