• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Default Value on Dropdown

guyfromnola

New Member
I've been working with the following issue, to the point of pulling my hair out.

I have 3 tables - ENTITIES, CONTACTS, and REGISTRATIONS

There is a databasejoin (related data link) between ENTITIES and CONTACTS. There is also a databasejoin (related data link) between ENTITIES and REGISTRATIONS.

Each CONTACT is tied to one ENTITY. When a user logs into their profile, they have a menu link to view their list of REGISTRATIONS, and the option to add new REGISTRATIONS. However, since the user is not initiating an add from the parent table using the related data add (something admins can do, but users cannot), the row id is not included in the url and therefore does not default to the related ENTITY of the CONTACT.

I have a user plugin running that defaults the new REGISTRATION to be tied to that CONTACT. However, the database join that exists is currently rendered as a dropdown with a list of all ENTITIES. What I want to do is have that dropdown default to the ENTITY the CONTACT is tied to and make it read-only for users. The current setup is fine for administrators, but as it currently stands, a user adding a new REGISTRATION has the autonomy to adjust the entity based on selecting one from the dropdown list.

I've tried to do this through PHP eval and some other code snippets and tutorials I have found online, but nothing seems to have any effect in defaulting to the proper value from the dropdown list. I would assume that all I have to do is lookup the ENTITY value found in the CONTACT's record/profile, but I'm hitting a brick wall.

If anyone has any advice, can provide some valid code snippets, or anything insightful, I would be most grateful. Although I am not too fluent in writing the PHP snippet(s), I would imagine this is something easily done.

Thanks
 
Hi,

Please see this article for how to reference the form elements using the php plugin... then something like

Code:
$elemValue = $formModel->formData('some_table___some_value_raw');
$db = JFactory::getDBO();
$query = "SELECT * FROM some_table WHERE some_value = ".$elemValue;
$db->setQuery($query);
$row = $db->loadRow();
$myValue $row['some_value'];
$formModel->updateFormData('tablename___myotherelementname', $myValue, true);

Can't give you the exact code without knowing your table, field, and element names, but hopefully this will help get you started.

Dale
 
Hi Dale,

Thanks for the sample code. I have altered it to reflect what I assume would work, but I'm getting the error that follows the code snippet below:


Code:
$elemValue = $formModel->formData('contacts___entity_raw');
$db = JFactory::getDBO();
$query = "SELECT * FROM contacts WHERE entity = ".$elemValue;
$db->setQuery($query);
$row = $db->loadRow();
$myValue $row['entity'];
$formModel->updateFormData('registration___entity', $myValue, true);

Parse error: syntax error, unexpected '$row' (T_VARIABLE) in .../plugins/fabrik_form/php/php.php(391) : eval()'d code on line 6

Any insight on this?

Thanks
 
Also, what is the benefit or difference in running this as a form PHP script plugin versus including PHP code to be evaluated for the specific target element of the form for which this is intended?

Thanks
 
I'm guessing here... but if the query is returning more than 1 row, you need to use $db->loadObjectList(); or something that returns an array of rows. See http://docs.joomla.org/Selecting_data_using_JDatabase for more info on the db stuff. The actual error you are getting looks like a missing ; or something though - but your pasted syntax looks correct so I am thinking it may be the call itself.

There is no real core difference between element and form PHP as far as "what" can be done. However for offers a bit more control over when and is a bit broader in scope.

Dale
 
I follow what you are saying, but if I am simply looking to pull the single value that exists in the 'entity' element of the 'contacts' list for the currently logged-in user, there is only a single value to be returned; just the corresponding number (raw value) of the entity the contact is tied to. Would that correspond to the scenario of returning an array?

Maybe I'm mis-understanding the concept, but my generalization of this approach would be somewhat like...return the value of 'entity' element from 'contacts' list where the contact row is selected based on {$my->id}.
 
I am not sure what your data looks like... you can use:

Code:
var_dump($my_var);

In php code and it will "print" the value of the specified variable or array at the top of the page when loaded... just be sure to comment out or remove when no longer needed.

Dale
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top