Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to validate custom profile fields.

  • @enderpal444

    Participant

    I’m taking both a facebook and twitter url from my users so I can create links so I need to validate the url’s they submit. I found a nice little function to help me do that.

    `function validate_url(url)
    {
    if (/^(https?://)?((w{3}.)?)twitter.com/(#!/)?[a-z0-9_]+$/i.test(url))
    return ‘valid’;

    if (/^(https?://)?((w{3}.)?)facebook.com/.*/i.test(url))
    return ‘invalid’;

    return ‘not a valid link’;
    }`

    My question is how I can use this to check the url during profile edit and registration? I moved the bp template files to my child theme and started fooling around with the edit template under profiles but couldn’t really get anywhere. Any ideas on the best way to do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @karmatosed

    Moderator

    I think https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/validating-a-url-from-xprofile-field/ may provide a good starting point. If I am wrong though please let me know and I’ll take a look.

    @enderpal444

    Participant

    @karmatosed I had seen that but didn’t see an answer on how to do what I’m trying to do. I need a live validation to show the user whether or not their entry is a valid url for facebook or twitter.

    @enderpal444

    Participant

    @boonebgorges @djpaul Can you toss a dog a bone on this? I’d really like to know how to do it.

    @rogercoathup

    Participant

    If you want validation as they type / enter — hook some jQuery onto your form. [That’s standard jQuery form validation, for which you’ll be able to Google for plenty of examples]

    In your jQuery, you can call out (POST) to your PHP validation function. Look up AJAX in WordPress for details on how to do this – in particular you are interested in using admin-ajax.php and registering your function as an action. You then specify that action in your jQuery AJAX call.

    You might also want to look at some of the WordPress data validation functions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to validate custom profile fields.’ is closed to new replies.
Skip to toolbar