MyBB Community Forums

Full Version: PHP expert please help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am trying to check user filed fid6 if they are entering Facebook URL or some other one by can't make it work please help?

function cpfbbcode()
{
    global $mybb;


    $cpfbbcode = 'facebook.com';
    
        if(preg_match("/$cpfbbcode/", $userfields['fid6'], $match))
        {
		}
		else
		{
    
            error("some error");

        }
        }
if you dont need a complex search just use str_pos() instead

if(str_pos($userfields['fid6'], $cpfbbcode))
if(preg_match('#https?\://(?:www\.)?facebook\.com/(\d+|[A-Za-z0-9\.]+)/?#',$userfields['fid6'],$matches))
{
}

.
.
This is what I'd do:

function cpfbbcode()
{
	global $mybb, $db;
	
	$cpfbbcode = 'facebook.com';
	$uid = $mybb->user['uid'];
	
    $ufid = $db->fetch_assoc($db->simple_select('userfields', 'fid6', 'ufid = '.$uid));
	if(str_pos($ufid['fid6'], $cpfbbcode))
	{
		success("Valid");
	}
	else
	{
		error("Invalid");
	}
} 
Dear @pavemen, @effone and @Tankey thank you so much for your support I don't want to offend anybody so I won't choose best answer as they are all great ones! +1 for all of you Smile

Guys please one more question is this the correct hook

$plugins->add_hook("usercp_do_profile_end", "cpfbbcode");

Just checked all you codes return error Smile
Please guys how to make your code work? Or maybe tell me how to check
$userfields['fid6']
or user profile field
fid6
to see if user has entered facebook URL or some other?

Maybe something like this one?

function cpfbbcode()
{
    global $mybb;


    $cpfbbcode = 'facebook.com';
    
        if(strpos($userfields['fid6'], $cpfbbcode) !== false) 
        {
        
            error("some error");

        }
        } 
$userfields is not available, add it to the global list.
Thanks man by could you please post a complete code please
The above just means replacing

global $mybb;

with

global $mybb, $userfields;
Thanks from all the above which one do you think i should use to check if user has entered facebook URL not some other

PLease could anybody create a plugin because I have no idea how to make it work
Pages: 1 2