ThierryM
Member
Hi,
Here an exemple that I would have liked to find for my project. So I share this working solution.
My sources :
http://fabrikar.com/forums/index.php?wiki/php-form-plugin/
http://fabrikar.com/forums/index.php?threads/conditional-update-of-a-field-in-a-repeat-group.43315/
http://fabrikar.com/forums/index.php?threads/update-amount-in-repeat-group.27597/
My goal was to retrieve the Joomla userid from the email entered in a repeated group. So if the email existes in the Joomla_users table, the program add the userid belonging to the email in the table of the repeated group (group id=34 and table named "josto_adhesions_adultes").
The php code is in the form plug-in, process script "onBeforeProcess".
It's working fine. I hope this can help.
Regards,
Thierry
Here an exemple that I would have liked to find for my project. So I share this working solution.
My sources :
http://fabrikar.com/forums/index.php?wiki/php-form-plugin/
http://fabrikar.com/forums/index.php?threads/conditional-update-of-a-field-in-a-repeat-group.43315/
http://fabrikar.com/forums/index.php?threads/update-amount-in-repeat-group.27597/
My goal was to retrieve the Joomla userid from the email entered in a repeated group. So if the email existes in the Joomla_users table, the program add the userid belonging to the email in the table of the repeated group (group id=34 and table named "josto_adhesions_adultes").
The php code is in the form plug-in, process script "onBeforeProcess".
PHP:
/*Pr?paration des requ?tes */
$db = JFactory::getDbo();
$query = $db->getQuery(true);
/*r?cup?re le nombre d'enregistrements r?p?t?s dans le groupe n?34 ie
"adhesion_individuelle_josto_adhesions_adultes"*/
$repeatcount = $formModel->formData['fabrik_repeat_group'][34];
/*echo "<pre>";print_r($repeatcount);exit;*/
/*D?clare les tableaux qui stockeront les n? d'utilisateurs si retrouv?s */
$idsData = array();
/*parcours les enregistrements r?p?t?s un ? un*/
for($i=0; $i<$repeatcount; $i++ ){
$courriel = $formModel->formData['josto_adhesions_adultes___courriel'][$i];
// rajoute les donn?es une par une dans le tableau de stockage
if (!empty($courriel)){
$query="SELECT id FROM josto_users WHERE email ='$courriel'";
$db->setQuery($query);
$id = $db->loadResult();
if (!empty($id)) {
$idsData[$i] = $id;
}
else {
$idsData[$i] = 0;
}
}
else {
$idsData[$i] = 0;
}
}
/* Injecte les nouvelles valeurs dans les donn?es r?p?t?es */
$formModel->updateFormData("josto_adhesions_adultes___id_user_joomla", $idsData, true);
It's working fine. I hope this can help.
Regards,
Thierry