I seem to have hit a brick wall. I've created a registration form that saves to jos_users as well as extra data to a second (jos_chrono_members) table.
Now I've created a new form that should be filled by logged in users to place orders. The form would then save and email the user's name (from the jos_users table) and his address (from the jos_chrono_members table). I'd used V3 a while ago and used the profile plugin for something somewhat similar, but I can't figure out what to do in V4. any ideas?
In DFv4 the DB Record Loader Action in the DB Operations group is the equivalent of the old Profile Page plug-in. I think it has more or less the same options though I haven't yet got much experience with it.
Bob
Just use 2 DB Record loader actions, one connected to the user's table (although I believe that the user's name exists inside the user object), and the other one connected to the user's details table, you may use the WHERE boxes to load the proper record for the user using the user id which you may get from the User object, let me know if you can't get it to work and I can help with code snippets.
Regards,
Max
However, I'm still struggling a bit. I've created a cf_user_id field in my member details table (I'm sure I'd read somewhere that Cf will then update this with the user ID for me) but it's not updating.
Is there something I'm meant to add?
Well, if the form is saving the user data with registration then you will not have any data stored in the cf_user_id field because there is no user logged in.
Alternatively, you will find the new user id after registration with this piece of code:
$form->data['_PLUGINS_']['joomla_registration']['id']
So, in case of successful registration, you may use this code snippet inside a "Custom code" box before the DB save to the "details" table:
$form->data['cf_user_id'] = $form->data['_PLUGINS_']['joomla_registration']['id'];
Let me know how this works.
Regards,
Max
Thanks for the great support guys.
As I said before, i really appreciate your help with this - but I've gotten myself stuck again.
I used Max's script to save the data -
$form->data['cf_user_id'] = $form->data['_PLUGINS_']['joomla_registration']['id'];
and that worked fine.
however, I'm now trying to load data onto a form for editing, using 2 DB Record Loader actions - problem is, I can't figure out how to use the Where box (it says don't use WHERE...??). I've got a hidden field on the form that gets populated the users ID and would like my action to use either this or a variable in my where statement. I've tried a variable
= $my_id
and the field name =input_id
not sure I have the right syntax on the second one.Also, when saving the edited data, should I still just use the DB save action (won't that create a new record?)
thanks
doefoot
You are way ahead of me. I've not yet used the DB Loader.
I'd suggest that you need to take the MySQL statement you want e.g. WHERE `cf_user_id` = $cf_user_id
. . . except that we need to remove the WHERE and put the PHP bit in tags.
`cf_user_id` = <?php echo $cf_user_id; ?>
Or it may need to be`cf_user_id` = <?php echo $form->data['cf_user_id']; ?>
Bob
No joy. As soon as I put anything in the WHERE box I get the following error message on the form:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/justimag/public_html/msr/administrator/components/com_chronoforms/form_actions/db_record_loader/db_record_loader.php on line 34
Warning: Invalid argument supplied for foreach() in /home/justimag/public_html/msr/components/com_chronoforms/libraries/chronoform.php on line 203
At first i'd thought my php sucked (it does - I'm only about a week and a half in learning it) but even when I pasted your code I still get the same error - and don't understand what the error message means. what could I be missing?
Thanks
Could you please explain your form flow so I can tell you what you should do exactly ?
some notes, when using a DB record loader, the data will be loaded in the $form->data array under some key equals your Model id set in the action, so set your Model id to something like "User" and then you can find all the record data under
$form->data['User']
Or you may use the this formula without PHP:{User.cf_user_id}
But I read that you need to load the data for editing ? is that for the same logged in user ? if so then you need to get the logged in user id.
The error you are getting means that no data was found using the query provided (it should not give an error, this is a bug of course) so you will need to make sure that the query has some results.
Regards,
Max
Thanks for that - I no longer have an error message, but something's missing. Here's the workflow:
I've got this in the form code:
<?php
$user =& JFactory::getUser();
$reqname = $user->name;
$reqemail = $user->email;
$reqid = $user->id;
?>
with $reqid being sent to a hidden field, my_id. I've used this in the DB Record Loader's WHERE box ({User.my_id}). I've set the Load Fields and Load Under ModelID to 'yes', ModelID to User and Request Param is blank (I don't know what that does).
So, like I said, there's no error message, but neither are my fields being populated (wait, should I do that manually? if so what's the syntax?)
Oh, and also, once i do manage to get everything on the form, will a normal Db Save update the record or will it create a new one?
So far, this is for the first Db Record Loader to edit user's Joomla details(I'll add the second for his personal details when I get this right).
Sorry for the long post...
and thanks...
Please set "load under Model id" to "No" since I guess your fields names are not prepared to accept values in this format, this should load your fields with data I think.
will a normal Db Save update the record or will it create a new one?
As long as your form has a hidden field named with the same name of the table's primary key (cf_id) and has the value of the record.
Regards,
Max
I keep getting error messages, and when i don't, I still don't get any data in the fields (they are named the same as the database table fields).
I think it's time I asked to be spoonfed 😶 ...
What I've got so far:
to get data from the jos_users table, I've got the following:
DB Field: id
Table: jos_users
Request Param:
Load Fields: Yes
Model id: User
Load Under Model Id: No
Where Statement: There are the options I've tried and the various results
id = $reqid - get the error message. I loaded the $reqid variable in the form code
id = 80 and id='80' - no error message, but the form remains blank
{User.id} = id , id = {User.id} , `id` = <?php echo $id; ?> - all give error messages (I forget what other wacky combinations I tried)
so, my question: What should I TYPE in the WHERE box? (Mouth open - shamelessly awaiting spoon...)
Thanks
To load a User's data you need to identify the user to ChronoForms. Lets say that you do this with a URL parameter uid=68 where 68 is a valid User ID.
Then the form input elements must have the same name as the table columns you want to load.
The settings I used are:
Table : id
Request Param: uid
Load Fields: yes
Model ID: (empty)
Load Under Model ID: No
WHERE statement*: (empty)
This seems to work OK.
Bob
* This is not needed because we are using "param (uid) = column name (id)"
Thanks for the response.
I'm still getting the error message.
if it's any help, the for url is
index.php?option=com_chronoforms&chronoform=edit_user_details
I've entered the details exactly as you have.
I've noticed that if I try them with my member details table (the one with extra fields) it pulls the first record that has no cf_user_id (entered for testing only).
Does this have anything to do with not having any uid in my url?
Apologies for not responding sooner!😟
According to the settings in your last message, please try this code inside the WHERE box:
<?php
$user =& JFactory::getUser();
$user_id = $user->id;
?>
`User.id` = '<?php echo $user_id; ?>'
Assuming the user is logged in then this will load his record from the jos_users table.
If that doesn't work then please try to clear the "DB Field"
Let us know!
Regards,
Max
the workaround for now was to use `id` instead of `User.id`
So, the code in the WHERE box should now read:
<?php
$user =& JFactory::getUser();
$user_id = $user->id;
?>
`id` = '<?php echo $user_id; ?>'
However (yes, unfortunately, there is a however 😟 ) I've hit another snag.
The form does save the data to both tables, but it's not editing the records - it's creating new ones - in both jos_users and jos_chrono_msr_members (my second table).
I've got 2 DB Saves and for both the settings are:
Model ID: chronoform_data
Save under Model ID: No
if I set the model ID to 'yes' then i get the following error:
Warning: implode() [function.implode]: Invalid arguments passed in /home/justimag/public_html/msr/libraries/joomla/database/database/mysql.php on line 540
Any ideas...?
If it's creating new records only then your form submission doesn't have a field with the same name as the primary key of the table and a value equals the record you need to update, you may use a hidden field for this task, and you may also store the value in the session then grab it later before the save operation for more security.
Regards,
Max