Forums

Multi record loader showing user details only

kmedri 03 Aug, 2013
Hi I am trying to load the data only if the joomla user id = the cf_user_id

I have tried:
<?php $user = JFactory::getUser(); ?>
<?php foreach($form->data['WeeklyAssessment'] as $detail): ?> 
<div class="showweekly">
Name:<?php echo $detail['input_name']; ?>
<a href="index.php?option=com_chronoforms&chronoform=weekly_assessment&token=<?php echo $detail['cf_uid']; ?>">Edit</a>
</div>
<?php endforeach; ?>

Just not sure where to put the if or where

Also for some reason when clicking edit the form is not being populated. It has the correct cf_uid in the url (matches the entry in the database) however all the form fields are empty?

debug:
 [19] => Array
                (
                    [cf_id] => 20
                    [cf_uid] => bacbf73e6ba8b792ecc126ecdexxxxxx
                    [cf_created] => 2013-08-02 17:56:04
                    [cf_modified] => 0000-00-00 00:00:00
                    [cf_created_by] => 911
                    [cf_modified_by] => 0
                    [cf_ipaddress] => 222.222.222.222
                    [cf_user_id] => 911
                    [input_name] => my name
                    [input_email] => myemail@email.com
                    [input_week_number] => 3
                    [input_fitness] => tdhth
                    [input_demos] => iugliuuig
                    [input_personal_skiing] => hlkijh;io
                    [input_topics_covered] => iuh;oihg
                    [input_strengths] => hvkjhv
                    [input_weaknesses] => thluh
                    [input_progression_towards_goals] => kjnlkjhnl
                )

        )

)
Validation Errors: 
Array
(
)
Debug Data
db_multi_record_loader
SELECT `WeeklyAssessment`.* FROM `xxxxxx_chronoforms_data_weekly_assessment` AS `WeeklyAssessment`


Many Thanks in advance
Kevin
GreyHead 03 Aug, 2013
Hi kmedri,

If you only want to load records from the current user then I'd so that in the WHERE box of the DB Multi Record Loader.

Bob
kmedri 04 Aug, 2013
Great, got the first bit working by adding `cf_user_id` = '$user->id' in the WHERE box, just need to figure out why the form is not being populated on EDIT.
Could it be that the form is a multipage form?
GreyHead 04 Aug, 2013
Hi kmedri,

It shouldn't be a problem. Any data that is in the $form->data array when the Show HTML action runs will be used to populate the form. Basically that is anything in the calling URL, loaded from a Session or with the multi-page action, or created/loaded in an action before the Show HTML action.

Bob
kmedri 04 Aug, 2013
Going back to my last reply, adding:
`cf_user_id` = '$user->id'

only returns the data for user '0' (guest) account. What I would like to achieve is returning the logged in users data.

I have a SHOW HTML action and still no good, I have tried a couple of ways:

This is the form that submits the data to the database, this works, there is data in the db


This is a form I built trying to show and edit the data that the logged in user has previousley submitted using the the first form. This displays the data asked for except it either shows all users data with no WHERE query or just the guest users data with the `cf_user_id` = '$user->id' code


This is the form withe the load multiple db rows integrated. This only shows an empty form


The array is being built (see my first post). What am I doing wrong...
GreyHead 05 Aug, 2013
Hi kmedri,

If the results you are getting are from `cf_user_id` = '0' then probably $user->id isn't defined at that point? Try this in the WHERE box
<?php
$user =& JFactory::getUser();
echo "`cf_user_id` = '{$user->id}'";
?>

Bob
kmedri 05 Aug, 2013
Great that worked. starting to understand things a bit better thanks.

just need to be able to load the data in the form when using the edit button.

the url reflects the token and the correct cf_uid however the form is empty.
GreyHead 05 Aug, 2013
Hu kmedri,

Please try adding a debugger action to the On Load event after the DB Multi Record Loader and you should see the MySQL query that has been generated. Debugging that will help. I usually copy and paste them into PHP MyAdmin (or a similar tool) and check for any errors (you may need to replace the #__ with the correct table prefix first).
kmedri 05 Aug, 2013
Hi Bob,
the syntax:
SELECT `WeeklyAssessment`.* FROM `xxxxxx_chronoforms_data_weekly_assessment` AS `WeeklyAssessment` WHERE `cf_user_id` = '0'

Returns all the guest entrys, and also shows as being an array in the debugger
Array
(
    [option] => com_chronoforms
    [tmpl] => component
    [chronoform] => display_weekly_assessment
    [WeeklyAssessment] => Array
        (
            [0] => Array
                (
                    [cf_id] => 1
                    [cf_uid] => be88ceb2d2d2e7c533893864xxxxxxxx
                    [cf_created] => 2013-07-08 16:45:08
                    [cf_modified] => 0000-00-00 00:00:00
                    [cf_created_by] => 0
                    [cf_modified_by] => 0
                    [cf_ipaddress] => 118.93.22.222
                    [cf_user_id] => 0
                    [input_name] => Kevin
                    [input_email] => kevin@mydomain
                    [input_week_number] => one
                    [input_fitness] => 3r23
                    [input_demos] => qww
                    [input_personal_skiing] => q4tqt4
                    [input_topics_covered] => tq4r4r
                    [input_strengths] => 35tw34t34
                    [input_weaknesses] => q42r24r
                    [input_progression_towards_goals] => 2q4tq43r
                )
GreyHead 13 Aug, 2013
Hi kmedri,

It looks as though you have added a Model ID 'WeeklyAssessment' to the DB Multi Record Loader that you probably don't need. Does the load work if you remove it?

Bob
kmedri 14 Aug, 2013
Hi Bob,

If I remove the Model Id it replaces it with the table name and no data is loaded.

Just to clarify, I am using one form to submit the data to the database as above, except I have removed the DB Multi Record Loader, so on the On Load it just loads the form, and during On Submit it carries out a DB Save. This works as there is data in the DB.

The second form loads the data using a DB Multi Record Loader using param token and Model Id of WeeklyAssessment, with some custom code and a show html to display the data in a table, this form does not have any On Submit actions. This works as much as it loads the data from the users previous submissions of the first form. I then rely on pressing the Edit button to open the first form, which works, except there is no data.

I must be doing something wrong somewhere, the url contains the right token, cf_uid (/test?chronoform=weekly_assessment&token=af289b6470750f95f8d4a3a7xxxxxxxx)

Kevin
GreyHead 21 Aug, 2013
Hi kmedri,

I got your login but I don't know what form I'm supposed to be looking at or how you are calling it, or how to reproduce whatever the problem is . . .

I opened up the weekly_assessment-Copy form and can see there that you have a token set but no value in DB Field - presumably you need to have cf_uid if you are using that as the identifier.
The form doesn't have an Authenticator to limit it to logged in users so you will get user_id = 0 for guests (like me).

Bob
kmedri 21 Aug, 2013
OK, sorry about that.

I use the weekly_assessment for inputting the data to the db, and then the display_weekly_assessment to pull the data back from the db for editing.
Thanks
Kevin
GreyHead 22 Aug, 2013
Hi Kevin,

Have you added the cf_uid?

Bob
kmedri 22 Aug, 2013
I added the cf_uid into the weekly_assessment form and still did not populate the form.
It displays the correct data with the edit button, but when pressing the edit button it opens an empty form
GreyHead 22 Aug, 2013
Hi kmehdri,

And what is the URL created by the Edit button? Doesn't that use cb and the record id?

Bob
GreyHead 22 Aug, 2013
Hi khmedri,

But the form name there is weekly_assessment and that doesn't have a DB Record Loader (or am I getting confused here?)

Bob
kmedri 22 Aug, 2013
I use weekly_assessment to load an entry to the database and email a copy to the admin and the visitor.

This form contains fields for data input, a hidden field cf_uid and a submit button. It also has a load multiple records and does load the db with the data.

I then use the display_weekly_assessment to display the relevant db details for the user with the edit button for editing. The data displays great, complete with edit button.
The problem is when clicking the edit button the form loads but the fields are not filled with any data.
This topic is locked and no more replies can be posted.