verify text entered in custom profile field (Facebook, Twitt

Discussion forum for MOD Writers regarding MOD Development.
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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 ***/ 
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Volksdevil
Registered User
Posts: 2415
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil

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

Post 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 );
                    }
                }
My phpBB Extensions
Finally found great Website Hosting from :arrow: KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Twitch | My Volkswagen Corrado G60
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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 ;)
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Volksdevil
Registered User
Posts: 2415
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil

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

Post 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
Last edited by Volksdevil on Mon Jan 12, 2015 3:41 pm, edited 2 times in total.
My phpBB Extensions
Finally found great Website Hosting from :arrow: KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Twitch | My Volkswagen Corrado G60
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Volksdevil
Registered User
Posts: 2415
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil

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

Post 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-)
My phpBB Extensions
Finally found great Website Hosting from :arrow: KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Twitch | My Volkswagen Corrado G60
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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';
                    }
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
Volksdevil
Registered User
Posts: 2415
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil

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

Post by Volksdevil »

Cheers AmigoJack, I'll have a go with that as soon as I can. :)
My phpBB Extensions
Finally found great Website Hosting from :arrow: KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Twitch | My Volkswagen Corrado G60
nicotinemilk
Registered User
Posts: 13
Joined: Sun Nov 08, 2015 3:10 pm

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

Post 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.
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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.
Last edited by AmigoJack on Thu Nov 19, 2015 12:26 pm, edited 1 time in total.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
nicotinemilk
Registered User
Posts: 13
Joined: Sun Nov 08, 2015 3:10 pm

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

Post 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
User avatar
AmigoJack
Registered User
Posts: 6120
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

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

Post 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.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
nicotinemilk
Registered User
Posts: 13
Joined: Sun Nov 08, 2015 3:10 pm

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

Post by nicotinemilk »

Yes, that works perfectly!

Return to “[3.0.x] MOD Writers Discussion”