- Posts: 7
COMMUNITY FORUM
restrict extra field not registred users
- kolmao
-
Topic Author
- Offline
- New Member
Thanks in advance,
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- kolmao
-
Topic Author
- Offline
- New Member
- Posts: 7
But insert this code
<?php $user =& JFactory::getUser(); ?>
<?php if($user->get('guest') ==0 ): ?>
--- extra fields code ....
<?php endif; ?>
Dont hide all the fields? I need only hide the field of price to guest, but they can see the rest of fields.
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
inside the foreach loop first test for this->extrafield->name = 'name'
then test if the user is guest
show it if not guest
else
show it
endif
endif
endforeach
Please Log in or Create an account to join the conversation.
- kolmao
-
Topic Author
- Offline
- New Member
- Posts: 7
Can you tell me the code for test the field name?, I dont know this
Thank you very much for your help
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- kolmao
-
Topic Author
- Offline
- New Member
- Posts: 7
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('Additional Info'); ?></h3>
<ul>
<?php $user =& JFactory::getUser(); ?>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<?php if($extraField->name == 'Price'): ?>
<?php $user =& JFactory::getUser(); ?>
<?php if($user->get('guest') ==0 ): ?>
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<br class="clr" />
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
But now, with user logged, show only the "Price" and whith guests hide all fields
Sorry for the inconvenience...
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
It is not first time you help someone through private messages. Write it here in public. It can help someone other..
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
@kolmao I think if you combine the statements into something like
<?php if($extraField->name == 'Price' && $user->get('guest') ==0 ): ?>
it will work for you (not tested)
Lots of good help with phphere
Please Log in or Create an account to join the conversation.
- kolmao
-
Topic Author
- Offline
- New Member
- Posts: 7
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
Try to work with it and make it work for one extra field. Maybe solution is to disable automatic listing od all fields then call tehm all one by one, and remove one special for Guests.
<?php$user =& JFactory::getUser(); if($user->get('guest') == 0) : ?> <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <?php endif; ?>
Please Log in or Create an account to join the conversation.
- kolmao
-
Topic Author
- Offline
- New Member
- Posts: 7
I'm not sure how to do that
This is the loop code
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields -->
<div class="itemExtraFields">
<h3><?php echo JText::_('Additional Info'); ?></h3>
<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField):?>
<li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
<span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<br class="clr" />
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
Where should I insert the code you posted?
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
With this "User" code.
But it is just for testing. It works. I used2 browsers, one logged, another not. One show fields for logged, one don´´t.
I cannot make it work for just one field. Mybe you will have better luck.
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
<?php endif; ?>
when you test.
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
With this code above you can easy hide "div" and "class".
One extra filed = one div/class.
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
<?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="k2ExtraFields"> <h3><?php echo JText::_('Additional Info'); ?></h3> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField):?> <!-- insert code to test for registared and wether or not to skip here Replace HideField2 with name of your extra field--> <?php $user =& JFactory::getUser(); ?> <?php if($extraField->name == "HideField2" && $user->get('guest') ==1) { ?> <!-- prove it works - delete the text below after testing --> field omitted <?php } else { ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="k2ExtraFieldsLabel"><?php echo $extraField->name; ?>:</span> <span class="k2ExtraFieldsValue"><?php echo $extraField->value; ?></span> </li> <?php } ?> <?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- kolmao
-
Topic Author
- Offline
- New Member
- Posts: 7
Now hides only the specified field.
Thank you very much, now everything is perfect.
Please Log in or Create an account to join the conversation.
- BBC
-
- Offline
- Platinum Member
- Posts: 663
Please Log in or Create an account to join the conversation.