MyBB Community Forums

Full Version: [Guide] Adding Color Hex Validation in Nickman's Form Manager 2.0 Plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This will add Color Hex Validation in Nickman's Form Manager 2.0 Plugin.

In the plugin files, open:

admin/modules/config/forms.php

and find all instances of (there are four):
"5"=>"All letters"

change those to:
"5"=>"All letters","6"=>"A Color Hex"

save the file and close.

Now open:
forms.php (included to be uploaded in the site root).

and find this at near-about line no. 602:

if ($items[$name]['type'] == 5)
	{
		validate_letters($name,$value);
	}

add just after that (before final closing curly brace '}' of 'validate' function:

if ($items[$name]['type'] == 6)
	{
		validate_colorhex($name,$value);
	}

Now find this function near about line no. 645:

function validate_numeric($name,$value)
{
	if (!is_numeric($value))
	{
		form_error("The field $name was not a number");
	}
}

Add just after that:

function validate_colorhex($name,$colhex)
{
	if (!preg_match("/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/",$colhex))
	{
		form_error("The field $name was not a valid color hex code");
	}
}

Save the file and close. Re-upload two modified files, activate the plugin.
Now you have additional option for the fields with Color Hex Validation Big Grin