Skip to:
Content
Pages
Categories
Search
Top
Bottom

validate xprofile field's value on registration


  • crazyboy
    Participant

    @crazyboy

    hi, I want to validate xprofile field’s value on registration

    I have a referrer field (field id=3) on xprofile field on registration & I want to validate if the referrer is exist on my site, validate the referrer is one of the users that exist on my database on table ‘wp_users’.’wp_login’

    could some one help me with the code?

Viewing 3 replies - 1 through 3 (of 3 total)

  • shanebp
    Moderator

    @shanebp

    So the field should contain the user_login of one of the members?
    Untested – try this in bp-custom.php.
    Put the correct field name in ‘your-field-name’.

    function crazy_check_referrer() {
      global $bp, $wpdb;
    
      $referrer_field = $_POST['your-field-name'];
    
      $referrer_check = $wpdb->get_var( "SELECT ID from wp_users WHERE user_login = '$referrer_field' ");
    
      if( $referrer_check == NULL ) 
        $bp->signup->errors['your-field-name'] = __('That person was not found','buddypress');
    
    }
    add_action('bp_signup_validate', 'crazy_check_referrer');

    crazyboy
    Participant

    @crazyboy

    thanks
    here is the code on functions.php

    function validate_referrer()
    {
      global $bp;
      global $wpdb;
      $referrer = $_POST['field_3'];
      $members = $wpdb->get_var("SELECT * FROM wp_users WHERE user_login = '$referrer'");
    
      if (!$members) {$bp->signup->errors['field_3'] = __('Please enter the correct referrer','buddypress');}
    }
    
    add_action('bp_signup_validate', 'validate_referrer');

    crazyboy
    Participant

    @crazyboy

    how about to validate field with format:
    Uxxxxxxx (xxxxxxx is number)
    ex: U1234567

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘validate xprofile field's value on registration’ is closed to new replies.
Skip to toolbar