I'm trying to build a database that logged users can fill through a form. It's for a medical research where every user has to fill the data of every patient he treats. Many data had to be updated in a couple of months, so I need that the user can access to al the records he has fulfilled to update them.
I've read around forum and faqs but I don't understand how it works.
In my page at first I have a login page (joomla) that grants access to my form. I've created a submit button and in the Setup tab of my form I've put a DBRead action in the first position of OnLoad area. In the submit area I added a DBSave action. In both cases I selected the table of my form.
In the DBRead I enabled multi read and in the DBSave I don't understand the next phrase under the Multi Save option:
"Save multiple records, this should be disabled in most cases, unless your form submits numerically indexed list of records."
How do I get my form to numerically index list of records?
How can I have my page showing the records every user has filled (only the ones every user fills) in a list so he can edit and save this records, at the beginning?
How can I put a button in that beginning page with the records to give the user to add a completely new record?
Thank all in advance,
Andres.
Correction:
How can I put a button in that beginning page with the records to give the user the option to add a completely new record?
Let's see if I understand what you want:
(1) A registered user can log in and enter multiple patient records using an input form.
(2) The user can edit any of the records which her/she created, but no on else's..
If that's the case, then you can use the user_id which is unique for each user and is saved in your database when the record is created (unless you unchecked it when you created the table for your form). To edit records, you want to pull those with the user's user_id..
I'm doing something similar but instead of using multiple record reads, my approach is to use two forms and one ChronoConnecitivity connection:
The first form is for record creation and it saves the user_id with the other data.
The connection uses the user_id to list the user's database records.
The user can select one of the records which in turn opens the second form with the data loaded so it can be edited.
The user must be logged in to allow the connection to get his/her user_id and use it to pull their records out of the database.
If this sounds like what you want, let me know and I can give you some more detail on how I'm doing it.
Jerry
Sounds exactly what I want. Like also your approach. Give me more details please and thank you very much.
Andrés.
Basically, you already have the first form created. For discussion, let's call it Form1.
If you don't have ChronoConnectivity (CC) installed, then download and install it.
Create a CC connection, let's call it ShowMyRecords.
Remember, this is to show a summary list of records.
On the Models tab
Model Title: enter a simple model name, eg, health
Table name: select your database from the dropdown list
Conditions: enter the following code
<?php
$user = JFactory::getUser();
return array("user_id" => $user->get("id"));
?>
This gets the user_id for the logged in user.
Fields: include the field names you want loaded or leave blank to load all of them
On the Front List tab:
Settings sub-tab:
Display Type: select Table for a simple list
Columns list: include the fields you want listed for each record. Since we defined a Model, include the model name with the filed name. You also include the Column title for the field. For example, say my table included the fields id, name, and phone I'd enter:
health.id:Record
health.name:Name
health.phone:Phone
This will show the record number, name, and phone number for each record for the user_id.
To the Columns list I add also add
_EDIT_:Edit
_DELETE_:Delete
These add two links to each record: Delete the record, or Edit the record.
Sortables: if you want to allow the user to sort the list you can specify the sorting fields here, eg, health.name
Filters: this is where you filter based on the user and comes from the php code above; enter $user->id
Actions sub-tab
Select edit
Form event: this is the name of the second form which we need to create. Call it Form2
Permissions sub-tab
This can get a little tricky depending on how your user groups are defined. Basically,if the user group is a child of Public, then you can set the Public permission to Allowed for all the different form actions (index, view, etc) and those will be inherited. Otherwise, you can set the individual user group permissions.. Set them for all actions.
Save the connection.
This is getting lengthy so I'll post another reply for the next part.
I left something out in my previous post.
In Actions sub-tab
edit
Form event: enter Form2:load
That identifies the form and tells CC to load it. It might run OK without the :load suffix, but unclude it for correct syntax.
The record field "id" I referred to in the previous post is the first field and is a sequential number assigned by the system when the record is created. A number of posts in the forum suggest renaming the field to something like cf_id when creating the table for a form. I do that also, but for this discussion since I already referred to it s just "id" will continue to do so.
You can use your input form as your edit form, but I find it easier to use a second form since I can then control which fields can be changed. I think it makes for easier form use also, but that's just me.
Start by making a copy of Form1.
Open the copy for editing and change its name to Form2
Because the form was called from the connection, we need to add the Model name to each filed name.
On the Layout tab, Edit each element and change each field name to health[field name]. For example, if you have a field named phone, change it to health[phone].
If there are any fields you don't wan the user to edit, change their Load status to Disabled. They'll appear grayed-out on the form and can be changed.
Add another text element with a fieldname of health[id] and set its Load status[/] to Hidden.
On the Setup
[i]On load
What you have in here depends on how your form is set up but it should end with the HTML (Render form) action.
Do not include a DB Read action - the connection tells the form which record to load when the user selects the edit link.
On submit
Again, actions depend on your form set up but do not include a [i]DB Save{/i] action.
Instead add Connection Action from the External Apps category.
Edit it:
Connection name: ShowMyRecords
Connection's action: save
This will cause the existing record to be replaced by the edited version.
Now you need to setup your menus to allow input and editing only by registered users. User groups who are able to create and modify records should be assigned to a particular access level. Let's call ours Recorders.
Create a menu item for the input form
Details tab
Menu Title: Create Patient Record
Menu Item Type: CrhronoForms5 form
access: Recorders
Options tab
Form Name: Form1
Create a menu item for the connection records list
Details tab
Menu Title: Show My Records
Menu Item Type: Connection view
access: Recorders
Options tab
Connection Name: ShowMyRecords
OK, now what should happen:
When a registered user who belongs to a user group assigned to the Recorders assess level logs in, they will see two menu items:
Create Patient Record
Show My Records
Picking the first will open Form1 for imput.
Picking the second will show a list of only that user's records (the list will be empty if the user doesn't have any).
Each record will have a Delete link and an Edit link
Clicking the Edit link for a record opens Form2 with that record loaded for editing.
Caution: selecting Delete deletes the record without any "Are you sure?" warnings.
Full disclosure
There is one thing in particular I haven't been able to figure out yet. If you use a multi-choice field like Checkbox Group, the edit form only shows the last choice in the list. Multi-choice values are generally stored as a comma delimited string in a single field. When it's read, because of the commas each choice is successively loaded into the same "variable" so only the last one survives. This isn't a problem with Radio Boxes since only one value is allowed.
So be advised if you're using Checkbox Groups.
Pleas excuse the random [/b], [/i], etc, tags. I wrote the text in an editor and pasted it here and missed a few things.
Jerry
This is really a tutorial. Thank you so very much. It works fine except for the checkbox groups, but I'm looking for GreyHead's help.
I want to tell you, that indirectly you and the other people of the forum, special mention to GreyHead, have helped to make simpler a clinical investigation that I hope will have great impact at our local hospital (we don't have economical possibility to have an expert for the database so I'm trying to make it possible).
Thank you again.
You're welcome.
I did figure out a work-around for the multiple-choice check boxes.What I did was instead of using an edit link from the Connection, I used a view link and opened a third form. This form uses a DB Read action in On load to load the record selected in the Connection list. In the On Found section of DB Read, I inserted a Custom Code action with php code containing the explode commands for the check boxes.
For example, I have two multiple-choice checkbox groups: pos_sought and pos_type. I'm using a Model named look. This is the php code in the Custom Code action:
<?php
$form->data["look"]["pos_sought"] = explode(",", $form->data["look"]["pos_sought"]);
$form->data["look"]["pos_type"] = explode(",", $form->data["look"]["pos_type"]);
?>
When the form loads, all the correct choices are shown in the groups.
In On submit I have a Handle Arrays action right before a DB Save action.
So instead of having the Connection save the record, I do it using the third form.
As before, you have to remember to include the id (or cf_id) field on the form to link the record to it from the Connection.
This process may be a bit more work and create an additional form, but it works for forms with or without multi-choice check boxes.
Good luck.
I don't understand if I have to substitute the second "editable" form for this new one or do I have to make work three forms at once. If it is so I'm lost how to connect them. Could you explain me a little bit in detail the design of it all?
Another question, I'm planing to add multipliers in my form, does it affect this design?
Thanks in advance.
Andrés.
My approach may not be the most efficient, but it works.
I use three forms:
(1) For initial input
(2) For display - this one uses Custom Code to format data display instead of the default form fields.
(3) For editing
I initially used the same form for (1) and (2) but the problem I ran into was that I used WYSIWYG for input and when the second form displayed the information, it showed the html code instead of applying it, Bedsides, using Custom Code allows be to do nicer formatting.
Using a third form allows me to control what fields can be modified by the user.
I use two Connections:
(1) To list all the records in the database (or filtered if needed) so any user can a record to view. This choice loads Form (2).
(2) To list only the records which belong to the user who is logged in. This allows the user to edit/delete their record(s).
I'm working on these on a test site and would be happy to provide you a user login so you can try out what I have so far. I'm at a meeting right now but can PM you later today or tomorrow.
JM
I'm not sure about multipliers, since I haven't worked with them, so I don't know how they would affect your design. Maybe someone else can comment on that.
To show you what I tried to explain, after some trial and error I built a simple Patient Records Management System. Rather than detailing it all here, I've attached a pdf file describing the forms and connections I created and the table structure.
I've also attaching a forms backup file (forms.cf5bak) which (should) contain the forms. I have a connections backup file (connections.cc5bak) which I tried to attach, but the forum says it won't allow it is an attachment. I'll rename it connections.txt and try that. If it works, be sure to rename it if you download it.
Jerry M
I was going to mention, but forgot, that you should add a database extension to Joomla which allows you to view/modify the structure or contents of a table. There's a number of good extensions out there, but one that I like because it's easy, flexible, & free is VJ Database Tool. It's handy to have a tool like this that lets you look at the content of a record when trying to debug a DB Read or DB Save on a form.
You can do the same using a database manager thru CPanel, but it's just so much handier to access tables from inside Joomla.
JM