Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
2.0k views
in Q2A Core by
Users can complete their profile by setting the default fields and the custom fields (that I created for them). When someone access the user's profile, he can see all information about the user but, if the user has not set some fields, the labels are visibile without any info.

Is there a way to display that field labels only when the user set that fields?

I'm not sure if I have the possibility to work with qa-theme.php file or just with a core file.

1 Answer

+1 vote
by
edited by
 
Best answer

If you're not afraid changing the core-files:

  1. open qa-page-user.php
  2. search for     foreach ($userfields as $userfield)
  3. add "if ($valuehtml) {...}" around the array-constructor for $qa_content:

if($valuehtml){
  $qa_content['form']['fields'][$userfield['title']]=array(
    'type' => $fieldsediting ? 'text' : 'static',
    'label' => qa_html($label),
    'tags' => ' NAME="'.$fieldname.'" ',
    'value' => $valuehtml,
    'error' => qa_html(@$errors[$fieldname]),
    'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
  );
}

 

that's it   :)

 

[refering to comment: changed from $value to $valuehtml]

by
Thank you very much for your help! :-) The solution is near the perfection but I noted a little problem: when a user sets his location field, that comes after the website field, the website field label still remain visibile even if the field is empty. Strange mechanism...
by
sick!  -> you're absolute right - we have to check against $valuehtml and not against $value.
I've corrected this also in my first posting above now.
by
Now the solution is perfect!!! Thank you very much for your help! :-)
...