Hello,

I've created a custom field (field_interests) in the user profile configuration. This field is a List(text) type with several options shown as check boxes. The following options are:

Soccer
Football
Baseball
Hockey

Each user of the site can choose any or all of the options, which are then used on the front end of the site. I want to display all of the available options and use CSS to style the options that are checked (true).

HOW DO I:

  1. Render the list of options directly in user-profile.tpl.php?
  2. Check whether each field is true/false?

All my other fields render fine using the following format:

<?php print strip_tags(render($user_profile['field_name'])); ?>

I'm sure it has something to do with the list field type that I'm not getting. Thanks for reading!

Comments

unifiedac’s picture

Here was my solution:

$my_interests = field_info_field('field_my_interests');
$user_id = $acc->uid;

foreach ($my_interests['settings']['allowed_values'] as $each_interest)
{
    if($query = mysqli_query($db, 
    "SELECT field_my_interests_value 
    FROM field_data_field_my_interests 
    WHERE entity_id = '$user_id' 
    AND field_my_interests_value = '$each_interest'"))
{   
	while($row = mysqli_fetch_assoc($query))
	{   
		foreach ($row as $value)
		{
		    echo '<div class=\'my_interests\'>' . $value . '</div>';
		}
  	}
	   
	mysqli_free_result($query); 
} 


}