• 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.

BUG - isuniquevalue on user field

rdiana

Member
Dear Friends,
I've applied the Fabrik validation "isuniquevalue" on a user field (setted on "ID") to allow only one record for each user. Unfortunately the plugin seems not working only with the USER field (it works fine with other fields). Can you verify this bug?

Thank you,

Roberto
 
It's not so much a bug, more that it just won't work with the 'user' element, just because of the way the user element works internally.

You'll probably have to roll your own validation in PHP, and use the php validation rule. The code would be something like this:

PHP:
$listModel = $elementModel->getlistModel();
$element = $elementModel->getElement();
$list = $listModel->getTable();
$db = $listModel->getDb();
$lookuptable 	= $db->NameQuote($table->db_table_name);
$user = JFactory::getuser();
$data = $user->get('id');
$data = $db->Quote($data);
$query = $db->getQuery(true);
$query->select('COUNT(*)')
	->from($lookuptable)
	->where($element->name.' = '.$data);
$pk = FabrikString::safeColNameToArrayKey($table->db_primary_key);
$rowid = JRequest::getVar($pk, '');
if (!empty( $rowid)) {
	$query->where($table->db_primary_key .' != '.$db->Quote($rowid));
}
$db->setQuery($query);
$c = $db->loadResult();
return ($c == 0);

NOTE - you'll need to update to latest github for this to work, as I just had to rename $element to $elementModel in the PHP plugin.

-- hugh
 
Thank you very much, Cheesegrits. But does it exist a standard method to allow, to each user, the addition on ONLY ONE record in a database table? In other words, is it correct, as in my case, to use a valitation rule (isuniquevalue or areuniquevalue) or other ways can be performed without any addition of PHP code?


Best regards,
Roberto
 
I think the way to go is to have a hidden field in your form to record the ID of the user when he submit its record.
Then use the PHP form plugin to perform a check when accessing the form (onBeforeLoad) : if the user ID of the connected user is already present in the database table, the user is redirected to a page or message specifying only one entry is allowed; if not, he has access to the form.
 
Dear Cheesegrits,
where can I paste your code? si it a Condition for the PHP Validation Rule of an element plugin? and what plugin? and, in this case, what PHP code and what condition (substitution)?

Thank you...
 
hi there is a PHP validation rule in the code at github that you can download and install.
It should allow you to paste the php in a text area
 
Dear Friends,
I've solved by performing, on onBeforeLoad Form-event, the following PHP code:

$app = JFactory::getApplication();
$db =& JFactory::getDBO();
$query = "SELECT count(*) FROM `res_labs_al` WHERE `user_id` = {$my->id}";
$db->setQuery($query);
$value = $db->loadResult();
if ($value > 0) {
$app->redirect(JRoute::_('index.php?option=com_fabrik&view=list&listid=4'), JText::_('Already reserved') );
}


which works fine!.
Thank you very much for your suggestions.

Cheers,
Roberto
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top