Forums

Hide field based on user data

guillome 21 Jul, 2015
Hello,

is there a way to hide/show a field based on the logged in state of a user in joomla? I can get the username, logged data, but I don't know how to enable or disable only one input box from PHP with the onload section?
I know I should create a custom code probably, but how can I call hidden property of a field object and set it?

thanks
GreyHead 22 Jul, 2015
Hi guillome.

I would do it with CSS something like this in a Custom Code action in the On Load event before the HTML (Render form) action
<?php
$user = \JFactory::getUser();
$display = 'none';
if ( $user->id > 0 ) {
  $display = 'block';
}
$jdoc = \JFactory::getDocument();
$style = "#form-row-input_name {
  display: {$display};
}
";
$jdoc->addStyleDeclaration($style);
?>
Swap over the 'block' and 'none' as you need.and add your input_name

Bob
guillome 22 Jul, 2015
Thanks Bob, this is awesome!!! I works and I really like its simplicity.
This topic is locked and no more replies can be posted.