verify text entered in custom profile field (Facebook, Twitt

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

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

Post by AmigoJack » Mon Mar 10, 2014 7:20 am

  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 worst thing about censorship is ███████████

User avatar
Volksdevil
Registered User
Posts: 2413
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

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

Post by Volksdevil » Mon Mar 10, 2014 8:39 pm

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 Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
My Volkswagen Corrado G60 | Opel Manta Owners Forum

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Mon Mar 10, 2014 9:03 pm

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 worst thing about censorship is ███████████

User avatar
Volksdevil
Registered User
Posts: 2413
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

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

Post by Volksdevil » Mon Mar 10, 2014 9:06 pm

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 Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
My Volkswagen Corrado G60 | Opel Manta Owners Forum

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Mon Mar 10, 2014 9:21 pm

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 worst thing about censorship is ███████████

User avatar
Volksdevil
Registered User
Posts: 2413
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

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

Post by Volksdevil » Mon Mar 10, 2014 9:28 pm

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 Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
My Volkswagen Corrado G60 | Opel Manta Owners Forum

User avatar
AmigoJack
Registered User
Posts: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Tue Mar 11, 2014 7:39 am

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 worst thing about censorship is ███████████

User avatar
Volksdevil
Registered User
Posts: 2413
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

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

Post by Volksdevil » Thu Mar 13, 2014 12:56 pm

Cheers AmigoJack, I'll have a go with that as soon as I can. :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
My Volkswagen Corrado G60 | Opel Manta Owners Forum

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 » Wed Nov 18, 2015 10:59 pm

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: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Thu Nov 19, 2015 7:50 am

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 worst thing about censorship is ███████████

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 » Thu Nov 19, 2015 12:16 pm

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: 4999
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

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

Post by AmigoJack » Thu Nov 19, 2015 1:17 pm

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 worst thing about censorship is ███████████

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 » Thu Nov 19, 2015 10:22 pm

Yes, that works perfectly!

Locked

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

Who is online

Users browsing this forum: No registered users and 14 guests

cron