Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:57:55+00:00 2026-06-17T14:57:55+00:00

I have a Drupal 7 site, and I would like to print out inside

  • 0

I have a Drupal 7 site, and I would like to print out inside the profile page some field content, according to the role of the profile user (not the logged in user).
I need to show a specific field only if the profile owner does not have role autor:

<?php
  if (!in_array('autor', array_values($user->roles))) {
print drupal_render(field_view_field('profile2', $profile['main'], 'field_nombrecompleto1', 'value'));
  }
  else {print "yada yada";}

Note: The profile field in question, is a rofile2 field and not a core profile one.

What´s wrong with that code? Because it will print out the field in question in any case, regardless of the role of the profile owner.

I´ve tried this other code, and in this case the field won´t print out in any case:

<?php
if (is_array($user->roles) &&
    in_array('authenticated user', $user->roles) &&
    !in_array('autor', $user->roles)) {
    print drupal_render(field_view_field('profile2', $profile['main'], 'field_nombrecompleto1', 'value'));
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:57:56+00:00Added an answer on June 17, 2026 at 2:57 pm

    Here is how this is accomplished in Drupal 7 when modifying the form for editing your profile:

    function MYMODULE_form_profile2_edit_main_form_alter(&$form, $form_state) {
      global $user;
      $roles = $user->roles;
      if(!in_array('authenticated user', $roles)) {
        $form['profile_main']['MY_FIELD_ID']['#access'] = FALSE;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have external proofreaders to work directly inside my Drupal site.
i would like to have a block on my drupal site(latest version) that displays
I need to develop a site on Drupal 7. I have some content types
I have a Drupal 6 web site and would like to use a node
I have created a drupal module which displays some reporting data. I would like
I would like to do a site in PHP/MySQL using either Drupal/Joomla/Wordpress that allows
Have a hyperlink inside of a h1... like so: <h1 id=site-name><a href=blah>blah</a><h1> I apply
I have a drupal site, and am trying to use php to grab some
I have a Drupal site on which users can enter CCK content by uploading
I have some site metadata I'd like to be changeable... for example, in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.