Force user to click Save?

Is there any way to force a user to click the Save button once they have opened a form?

Here's my situation: I have a list with a dropdown containing all the official roles in my organisation, plus a usergroup field so that each role has a specific usergroup. Once usergroups are assigned to roles, there is also a databasejoin dropdown linked to the User list, so you assign a role to a user and they automatically are added to the relevant usergroup.

The form has a php plugin which uses OnAfterProcess to insert the usergroup into the user’s record. This works perfectly.

Now, if a new user takes over that role, the form is edited and they get the usergroup. HOWEVER, I also need to remove the usergroup from the previous incumbent. So I have a second php plugin which uses OnBeforeLoad to delete the usergroup from the existing user’s record, before the other plugin comes into effect. This works perfectly too!

However, from a UX perspective, there is a slight glitch: if an unsuspecting user goes to edit a record but then closes the record without saving it (maybe they clicked the Edit button by mistake), the OnBeforeLoad instruction will have removed the usergroup from the User. If they click Save there’s no problem.

I’ve tried every alternative instruction on both php plugins but none work better.

So unless anyone has any ideas on how this can be achieved via the php plugin, my alternative is to prevent the foolish user from closing the form without clicking Save. Hence my opening question.
 
There is no way you can force user to click on the "Save" button unless you point a gun on him :) as user can just navigate away from your page or close the browser tab etc.

Couldn't you run also the usergroup removal script onBeforeProcess or onAfterProcess? That way it will not be triggered on form load and only on save.

If you do not want any usergroups selected on your form element, you could clear the selection with element javascript on form load. And if the form is not saved, original values are still intact in database.
 
Last edited:
Thanks @juuser , but I already tried onBeforeProcess and OnAfterProcess. The existing user in the role is not removed. I guess this is because at the time of either of those instructions, the user has already been changed. And I don't want to clear the usergroups because, for ease of client updating, I want them preset for each role. Once they've been set, I intend to hide the usergroups in the form so only the role-holder name needs to be changed.

I guess I'm trying to do too many conflicting things at once. I've put a warning on the form (in the Introduction text area) which hopefully will be sufficient.

Back to the gun at the head option.... ;)
 
In the form php-plugin you can access form's original data (origData), so you can get the original value of the user and remove the group from him/her.

I have learned to never trust users to follow any instructions or warning messages. So i always try to make things foolproof :)
 
Last edited:
Oooo, that sounds perfect. I've found that now in the wiki. Not sure how to place it in my current code though as I'm not using the wiki's recommended way to access the form data. Does that matter?
Here's my current code to remove the usergroup from the existing user:
$mydb = JFactory::getDBO();
$my_user_id = '{officers___name_raw}';
$my_usergroup = '{officers___access_level_raw}';
$mydb->setQuery("DELETE FROM #__user_usergroup_map WHERE user_id = ".$mydb->Quote($my_user_id)."AND group_id =".$mydb->Quote($my_usergroup));
$mydb->execute();

Where should I put the $origData = $formModel->getOrigData()[0]; line?
 
You can get the original "name" value like:

$origData = $formModel->getOrigData();
$my_user_id_orig = $origData[0]->officers___name_raw;

or without [0] like $my_user_id_orig = $origData->officers___name_raw; depending on element type (whether the value is array or not).

P.S. I was wondering why your code looked so good. Now I know :D
 
You've cracked it! It works perfectly with onBeforeProcess and using the [0] array.
Thanks so much, @juuser.
And you're right, I'm trying to make the whole app as foolproof as possible.
Now I can put the gun away... for a while... :D
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top