[SOLVED] Element permission depens on other elements

lke

New Member
Hi

i'm new and make some tests with fabrik.
It is possible to hide fields depends on other fields?

i.e.: it gives a field phonenumber and a field visible this options all, private. So when select private the phonenumber is not visible in details view.
I found that this is possible with javascript on element load, but this is not really hidden. In sourcecode the value is visible.

greets

Lars
 
Hi Lars,

What you can do is add a php form plugin and set it to the form onLoad event. Then use something like the following in the php code. I used a yes/no element for my "show" so I am saying if it is zero and we are in details view... change the phone number to X's. You can do whatever you like this is just to help get you started:

PHP:
$myShow = $formModel->data['ep_cal1___show'];
$myView = JRequest::getVar('view');
if($myShow == '0' && $myView == 'details')
{
  $formModel->data['ep_cal1___phone'] = 'XXX-XXX-XXXX';
}

Enjoy,
Dale
 
Hi


I found that this is possible with javascript on element load, but this is not really hidden. In sourcecode the value is visible.


Well, yes, it is "hidden", in the HTML sense of the word. Hidden doesn't mean "entirely removed from the page", it just means "not visible through the normal browser page view", either by using CSS's display=none attribute, or the HTM form element 'type=hidden'.

Dale's suggestion is a good one.

genyded - My only suggestion would be to use $formModel->getElementData('tablename___elementname') instead of accessing the $formModel->data[] array directly, as this insulates you against several potential gotchas. For instance, if you run a plugin onAfterProcess, the tablename___ prefix will have been removed from the data array keys. The getElementData() method has a "Hail Mary" check to see if the element name you are asking for exists without the tabe prefix, and / or exists in the dataWithTableName array (or whatever it's called), where we copy $data to prior to removing the tablename___ prefix when we actually write the table out.

-- hugh
 
Hi,

with your help it works fine. On the specified condition the value was changed and the original value is not visible.
It is also possible to remove elements from the formMode, like

Code:
$formModel->removeElement(....)

I think on the edit view it was not really good, when i change values.
 
Hi,

There is no PHP way to remove (that I am aware of). Only JS which as you already know - only hides. Regarding "edit" that is a form function outside of details view, so if you want this to apply there you can remove the $myView == 'details' part.

Dale
 
you can remove the $myView == 'details' part.
Yes i know, but when i only change the value onload Form, its a problem when the user save the profile.
The best way where an "caneditrow" plugin for elements where i can enter php code.

I have tested it with unset($formModel->data['table_field']) in onbeforeload php code, but this only remove the value not the element from view.
another idea was to set the access permission at php code, perheps then the element was not displayed.
 
Hi,
I have found a solution to hide elements, perheps somebody helps:

Create a Form php code on action "onCanEditGroup"

Code:
$elem = $formModel->getElement('table___element');
$elem->access->view = false; //to hide the element on details view
$elem->access->use = false;  //to hide the element on edit view


Lars
 
Here is my solution to hiding elements for certain users e.g registered in a form but showing them to SuperAdmins.
However still allowing the registered user to see the element result in list / details view.
1. Create a calc element > Save to DB = "No" > Ajax calc = "Yes"
Put in
Code:
$loggedin = '{$my->id}';
return $loggedin;
This will return the id of whoever is currently logged in be they admin or whatever
Add JS Validation
on load : When element "loggedin_id" < "630", show element "some_ admin_element"
Ensure all your superadmins have id's less than 630
2. Setup a element "user" > set as ID > save to DB = Yes > Hidden = Yes
Add JS validation
on load : When element "hiddenID" > "630", hide element "some_ admin_element"

This now means i can record the userid in the original form then if an admin needs to add an additional bit of info to the list they can do so e.g "record approved"
The registered user can see the updated record in their list but cannot see the element itself in edit view.

Dunno if theres an easier way of hiding form elements based on ACL but this works for me.
 
Hi,
I have found a solution to hide elements, perheps somebody helps:

Create a Form php code on action "onCanEditGroup"

Code:
$elem = $formModel->getElement('table___element');
$elem->access->view = false; //to hide the element on details view
$elem->access->use = false;  //to hide the element on edit view


Lars
hello.. i tried this in fabrik form plugin php but it didn't work at all..
I need to execute query to check user who is currently login, then decide to hide/show some elements.

can somebody help me please?? thanks
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top