MyBB Community Forums

Full Version: Only show profile fields in postbit if user has filled them out
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have some custom profile fields placed into the postbit such as location, but if the user hasn't filled out their location it just shows as:

Location: *blank space here*

Is there a way I could make items such as Location not show if it's not filled out by the user?
If you have the PHP Templates plugin installed, you can use that to check for a blank variable. Otherwise you could just use javascript.

In postbit_author_user, replace:
Location: {$post['fid1']}

with:
<script type='text/javascript'>if ("{$post['fid1']} ".length) document.write("Location: {$post['fid1']} ");</script>

Edit: This breaks if they add a backslash at the end of the field, I'll leave it here for preservation.
Fixed it by adding a space to the end, meaning any backslashes will only catch the space character and not break out of the quotes.


Edit 2: This could still have a hidden exploit, so I'd advise against using it. You should use the PHP Templates plugin instead, and properly escape the fields.