Edit Form if Condition = True; New Form if = False

hominid4

Member
Below is a simplified version of my Db tables. In short, what is needed is if a user's (`tbl_profiles___attempts` == `tbl_challenge___attempt`) then they are allowed to edit the form as many times they like, but if the user's (`tbl_profiles___attempts` != `tbl_challenge___attempt`) then show a new empty form to create a new row.

I've played with the list's can edit row, and such, but with no luck. Could I get a push in the right direction that may achieve what I'm needing - if it's possible?

tbl_profiles
id | userid | attempts
1 | 356 | 4
2 | 512 | 2

tbl_challenge
id | userid | attempt
1 | 356 | 1
2 | 512 | 1
3 | 356 | 2
4 | 512 | 2
5 | 356 | 3
6 | 356 | 4

"Attempt Challenge" `tbl_challenge` Form Menu Item Settings
Row id: -1
Key name: userid

User 356 has taken the challenge 4 times, user 512 has 2 times.
=======

Long-winded notes if needed:

A user registers for the site to complete a "challenge". When they register, the `tbl_profiles___attempts` is a hidden INT read-only field element and defaults to "1".

The user has X amount of days to submit the challenge form. The challenge form has a hidden read-only `attempt` INT field element that pulls the current `tbl_profiles___attempts` value on form load for that user and populates the submitted challenge row with that user's `tbl_profiles___attempts` value.

The user is able to go back and edit the `tbl_challenge` form as many times as they like within the 100 days, and the `tbl_challenge___attempt` element always uses the user's current `tbl_profiles___attempts` number. That works as needed.

After X amount of days a user first attempts the challenge, we run a cron script that adds +1 to that user's `tbl_profiles___attempts` value. After that, a user can re-take the challenge, so instead of editing an existing `tbl_challenge` row they will be creating a new row with the new +1 `tbl_profiles___attempts` value since (`tbl_profiles___attempts` == `tbl_challenge___attempt`) is FALSE on the first submission of the new challenge.

On a side note, a user is able to see their past submissions `tbl_challenge` list but I've removed the list's "Add" button and they access the `tbl_challenge` form via the "Attempt Challenge" menu item.

Thanks!

Fabrik v3.9.2 latest GitHub
Joomla v3.9.19
 
You can use a list copy with a prefilter profile-attemps == challengen-attemp and use this form in your rowid=-1 menu.
 
Thank you troester for your suggestion, unfortunately doing list copies wouldn't quite work for us (several reasons not to bore you with), however, based on your suggestion, if I just add a (tbl_challenge___attempt == tbl_profiles___attempts) prefilter to the one `tbl_challenge` list, the direct link to the `tbl_challenge` form via the "Attempt Challenge" form rowid=-1 menu item looks to work as needed. If (tbl_challenge___attempt == tbl_profiles___attempts) it shows the edit form, and if vice versa it shows a new form. I'll continue with the rest of my build-out to know for sure but so far it seems to be working just as needed.

And for viewing the past submissions I'll create a "Challenge Submission History" list menu item and I can apply the needed prefilters within that menu item's settings.

Thanks again!
 
Last edited:
Thanks chakib, but the Can Edit Row plugin was not what I needed, that was just allowing to edit the existing row or not, not creating a new form when needed as troeter's solution does.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top