1

I'm using Regular Lab's sourcerer to embed code in an article to modify users' email addresses once a questionnaire has been completed (anonymization).

I used this code to no avail:

$user = JFactory::getUser();
$user->setParam('email', NULL);
$user->save();

Would you have a clue as how it should be changed?

Thanks a lot for your help!

6
  • It is probably best to not modify their submitted email address in the database, but rather obfuscate it upon presentation. Alternatively, you might create a new custom field that holds the obfuscated email. As an alternative to nullifying, you could inject asterisks. Hopefully this feedback inspires you or another contributor to post an answer. Commented Dec 30, 2022 at 5:03
  • 1
    Thank you very much for your suggestion! Injecting asterisks is certainly an excellent option. If anyone knows how to do that with a PHP Joomla command, I would be deeply grateful.
    – Vlad
    Commented Dec 31, 2022 at 6:14
  • PHP, and the above code is PHP, runs on the server as part of building the page presented to the user. Once the browser has presented the page, PHP is no longer 'available' so what you are trying to do above is maybe something you have to do via Javascript and or AJAX or an API. Perhaps provide more context as to what you are trying to achieve or why you think you to clear email address and perhaps a more useful answer can be provided.
    – Irata
    Commented Dec 31, 2022 at 8:57
  • Thank you very much for your answer, and Happy New Year! I'm using Joomla websites to carry out questionnaire-based studies. Currently, I'm designing a study in which I need to invite users, and I must delete their personal identifiers as soon as the questionnaire is completed (username and password are randomly generated, but I must retain the actual email address to send reminders).
    – Vlad
    Commented Jan 1, 2023 at 15:05
  • Regarding the trigger event, I've often used JUserHelper::removeUserFromGroup or JUserHelper::addUserToGroup by embedding these commands with Regular Lab's sourcerer (in a regular article), and it always works fine to change groups and follow participant progression when necessary. I was therefore wondering what such command I could use to modify email addresses. Thanks for your help!
    – Vlad
    Commented Jan 1, 2023 at 15:05

1 Answer 1

1

Well, I finally found a PHP code (with the help of my wife) which works fine under Joomla 3.10 (thanks to Regular Labs' Sourcerer) and removes the email address of the current user:

$db = JFactory::getDbo();
$user = JFactory::getUser();
$userId = $user->get( 'id' );
$query = $db->getQuery(true);
$query = ("UPDATE `tablename_users` SET `email`=NULL WHERE `id` = '$userId'");
$db->setQuery($query);
$result = $db->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.