Page 2 of 2

Re: verify text entered in custom profile field (Facebook, T

Posted: Mon Mar 10, 2014 7:20 am
by AmigoJack
  1. Use phpBB's e-mail validation:

    Code: Select all

                    if( !function_exists( 'validate_data' ) ) {
                        global $phpbb_root_path, $phpEx;
                        include( $phpbb_root_path. 'includes/functions_user.'. $phpEx );
    
                        $aError= validate_data
                        ( array  // Data to validate
                            ( 'email'=> 'well... the e-mail address to be checked'
                            , array  // Validation settings
                                ( 'email'=> array  // For e-mail addresses...
                                    ( array
                                        ( 'email'  // ...check syntax
                                        )
                                    )
                                )
                            )
                        );
    
                        // Should only have a length of 0 or 1
                        if( count( $aError ) ) return $aError[0];
                    }
    Replace obvious literal.
  2. Add the field ident in uppercase:

    Code: Select all

    return 'URL_INVALID_'. strtoupper( $sIdent ); 
  3. Open /language/*/ucp.php and find:

    Code: Select all

    )); 
    Before, add:

    Code: Select all

        /*** 2013-06-14 BEGIN AmigoJack
            http://www.phpbb.com/community/viewtopic.php?t=2186548 ***/
        'URL_INVALID_MY_TWITTER'=> 'Twitter URI invalid',
        'URL_INVALID_MY_PLUSGOOGLE'=> 'Google+ URI invalid',
        ...
        /*** 2013-06-14 ***/ 

Re: verify text entered in custom profile field (Facebook, T

Posted: Mon Mar 10, 2014 8:39 pm
by Volksdevil
AmigoJack,

I've added the language in ucp no problem, but I'm struggling with where to add number 2. I've tried all sorts of combinations but can't get it to work.

Current attempt which just submits with no validation: :oops:

Code: Select all

                foreach( $aCustomCheck as $sIdent=> $sRE ) {
                    if( $field_data['field_ident']== $sIdent ) {
                        if( !preg_match( $sRE, trim( $field_value ) ) ) 
return 'URL_INVALID_MY_TWITTER'. strtoupper( $sIdent );
return 'URL_INVALID_MY_FACEBOOK'. strtoupper( $sIdent );
return 'URL_INVALID_MY_PLUSGOOGLE'. strtoupper( $sIdent );
return 'URL_INVALID_MY_INSTAGRAM'. strtoupper( $sIdent );
return 'URL_INVALID_MY_LINKEDIN'. strtoupper( $sIdent );
                    }
                }

Re: verify text entered in custom profile field (Facebook, T

Posted: Mon Mar 10, 2014 9:03 pm
by AmigoJack

Code: Select all

                foreach( $aCustomCheck as $sIdent=> $sRE ) {
                    if( $field_data['field_ident']== $sIdent ) {
                        if( !preg_match( $sRE, trim( $field_value ) ) ) return 'URL_INVALID_'. strtoupper( $sIdent );
                    }
                }
Of course ;)

Re: verify text entered in custom profile field (Facebook, T

Posted: Mon Mar 10, 2014 9:06 pm
by Volksdevil
Ah, I tried that one (Trying again now) but it just submits with no error, even with this in my twitter cpf:
witter.com/VW_Corrado_G60

REMOVED LOGIN DETAILS
http://www.corradog60.com

Currently have:

Code: Select all

                /*** 2013-06-14 BEGIN AmigoJack
                    http://www.phpbb.com/community/viewtopic.php?t=2186548 ***/
                $aCustomCheck= array
                ( 'my_twitter'=> '#^https?://(www\\.)?twitter\\.com/.+$#i'
                , 'my_facebook'=> '#^https?://(www\\.)?facebook\\.com/.+$#i'
                , 'my_plusgoogle'=> '#^https?://(plus\\.)?google\\.com/.+$#i'
                , 'my_instagram'=> '#^https?://(www\\.)?instagram\\.com/.+$#i'
                , 'my_linkedin'=> '#^https?://(www\\.)?linkedin\\.com/pub/.+$#i'

                );
                foreach( $aCustomCheck as $sIdent=> $sRE ) {
                    if( $field_data['field_ident']== $sIdent ) {
                        if( !preg_match( $sRE, trim( $field_value ) ) ) return 'URL_INVALID_'. strtoupper( $sIdent );
                    }
                }
                /*** 2013-06-14 END ***/
Thanks for helping...It does help me learn

Re: verify text entered in custom profile field (Facebook, T

Posted: Mon Mar 10, 2014 9:21 pm
by AmigoJack
That means it always accepted any value and a wrong input was never disallowed in the first place? If yes then it can only mean my_twitter etc. are not your field idents.

Re: verify text entered in custom profile field (Facebook, T

Posted: Mon Mar 10, 2014 9:28 pm
by Volksdevil
EDIT: Got it! :D :D :D << Quite happy with myself for perceiving although I did make a mistake, I forgot to also add these:
case 'URL_INVALID_MY_TWITTER':
case 'URL_INVALID_MY_FACEBOOK':
case 'URL_INVALID_MY_PLUSGOOGLE':
case 'URL_INVALID_MY_INSTAGRAM':
case 'URL_INVALID_MY_LINKEDIN':


And now I'm attempting to validate the email address into my cpf with ident 'my_paypal', I have tried a few things but again, I can't get it working :oops: I just need to check/validate that it's an email address (Any email address) entered with the '@' sign, and also containing the '.'

But thinking about it, are there email addresses without a dot? Not sure...So maybe just:
Something (Validate the @) Something

Thank you very much for the help AmigoJack. 8-)

Re: verify text entered in custom profile field (Facebook, T

Posted: Tue Mar 11, 2014 7:39 am
by AmigoJack
If you don't want to check for everything (EMAIL_INVALID, DOMAIN_NO_MX_RECORD, EMAIL_BANNED and EMAIL_TAKEN) you can also use a direct call, i.e.:

Code: Select all

                    if( $field_data['field_ident']== 'my_paypal' ) {
                        if( !preg_match( '/^'. get_preg_expression( 'email' ). '$/i', $field_value ) ) return 'EMAIL_INVALID';
                    }

Re: verify text entered in custom profile field (Facebook, T

Posted: Thu Mar 13, 2014 12:56 pm
by Volksdevil
Cheers AmigoJack, I'll have a go with that as soon as I can. :)

Re: verify text entered in custom profile field (Facebook, Twitt

Posted: Wed Nov 18, 2015 10:59 pm
by nicotinemilk
Thank you AmigoJack! This is great, but...

How would you go about adding one where the dynamic part of the link would be at the front of the URL? IE: Tumblr, where you have http://blahblahblah.tumblr.com ...

Code: Select all

, 'tumblr'=> '#^https?://(www\\.)?tumblr\\.com/.+$#i'
No idea.

I've been trying to hack it for an hour but I'm an idiot and am just getting a bunch of php errors... I'm so dumb. Blah.

Re: verify text entered in custom profile field (Facebook, Twitt

Posted: Thu Nov 19, 2015 7:50 am
by AmigoJack
That's because you don't seem to know regular expressions. A regexp for matching Tumblr URIs would be #^https?://[^.]+\\.tumblr\\.com/?.*$#i.

Re: verify text entered in custom profile field (Facebook, Twitt

Posted: Thu Nov 19, 2015 12:16 pm
by nicotinemilk
I am dumb, but I'll learn... Thank you for linking me info to regular expressions... Total noob.

I did run across some trouble with your fix, I think it still sought something after .com/bbb, which there isn't generally anything with tumblr URLs...

I did this

Code: Select all

'tumblr'=> '#^https?://[^.]+\\.?tumblr\\.com#i'
And it seems to be working fine, though I still have no idea what the i does... I know I need that hashtag in there as it seems to be like a bracket for the whole thing but, man, I'm clueless. Thank youuuuuuuuu Amigo

I WILL READ EVERYTHING ON REGULAR EXPRESSIONS AND BECOME MASTER OF THE UNIVERSE

Re: verify text entered in custom profile field (Facebook, Twitt

Posted: Thu Nov 19, 2015 1:17 pm
by AmigoJack
Actually I made a two mistakes, the correct expression is #^https?://[^.]+\\.tumblr\\.com/?.*$#i. Short description: supports both HTTP and HTTPS, expects a sub domain, trailing slash and more is optional.

Re: verify text entered in custom profile field (Facebook, Twitt

Posted: Thu Nov 19, 2015 10:22 pm
by nicotinemilk
Yes, that works perfectly!