Skip to:
Content
Pages
Categories
Search
Top
Bottom

Show Name Of XProfile Field that is in error when set to required


  • bcanr2d2
    Participant

    @bcanr2d2

    I am trying to show the field/fields that are required, but do not have any data.

    The following works when they are not set (during the members first visit to the site)

    //Check For Mandatory Profile fields - 
    $has_profile_pic = get_user_meta(bp_loggedin_user_id(), 'has_avatar', true);
    $has_cph_maxtopay = xprofile_get_field_data('Cost Per Hour');
    $has_age_ranges = xprofile_get_field_data('Age Ranges Of Children Able To Sit');
    $has_age = xprofile_get_field_data('Age');
    $has_suburb = xprofile_get_field_data('Suburb');
    $has_mobile = xprofile_get_field_data('Mobile Phone Number');
    $has_gender = xprofile_get_field_data('Gender');
    $member_type = xprofile_get_field_data('Member Type');
    
    //Check to see if profile items are set 
    //If not get error on screen to display
    if (empty($member_type)) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Member Type</li>';
    } else {
    if (empty($has_cph_maxtopay)) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Cost Per Hour/Max To Pay</li>';
    }
    if (empty($has_age_ranges)) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Age Ranges Of Children Able To Sit/Age Ranges of Kids</li>';
    }
    if (empty($has_age )) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Age</li>';
    }
    if (empty($has_suburb )) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Suburb</li>';
    }
    if (empty($has_mobile )) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Mobile</li>';
    }
    if (empty($has_gender )) {
    $error = $error + 1;
    $error_text = $error_text .'<li>Gender</li>';
    }

    I know I’m probably using the wrong function, but the xprofile_get_field_data will return the currently saved item for a user. Hence the reason why it works so well on a new user, the fields are emtpy. I want to check on the unsaved data when they click on save as well, so that I can show them what field is in error, and also highlight the field as well, so they can be guided visually to fill it in.

    IE They clear their cost per hour value, and I want to tell them it’s empty, and not just the generic Please make sure you fill in all required fields in this profile field group before saving.
    Let me know where I am going wrong with this.

  • You must be logged in to reply to this topic.
Skip to toolbar