DB Record Loader...newbie questions I'm embarrassed to ask

fdaley 22 Oct, 2013
I have always found it pretty easy to grasp new software during my business career but this is my first foray into web design so be gentle with me! I am pretty comfortable with MySQL but a complete beginner with php; most of my knowledge comes from a quick flip through "PHP and MySQL for Dummies" at the weekend.

I am using Joomla 3 on a Mac localhost using MAMP and want to use the DB record loader function so users of my site can enter information and edit it at a later date.

I followed the PDF tutorial "How to load one row from a DB table into your form" to the letter, creating the exact same form and database as in the tutorial.

I got to point 6, which says "We assumed in our scenario that we are going to pass the cf_uid field value in the form URL, but under which parameter name that field value will be passed ? Say we are going to call it “token”,
example:
index.php?option=com_chronoforms&chronoform=user_details&token=ff2119500f1a4ec2318c210bf681b0fe"
At this point I was wondering how anyone would be expected to remember a 32 character token and why it would end up in a URL (perhaps someone could explain) but I decided to go with it and replicated points 7 to 10.

On testing, the basic input form was fine but when I tried point 11 -"Then with the token param in the link, we can see the data of the corresponding record, yay!!🙂 index.php?option=com_chronoforms&chronoform=user_details&token=ff2119500f1a4ec2318c210bf681b0fe" (I substituted one of my test tokens from the MySQL database) all I got was the same old input form again when according to the tutorial I should have the user's data. I have tried logging in and out on various of my dummy users' logins but nothing works.

I also tried putting {field_name} fields in some custom code as suggested by point 13. and in the other article on http://www.chronoengine.com/faqs/2674-how-can-i-edit-a-record-from-a-database-table.html. I put in a custom code, as follows:

<?php
$user =& JFactory: :getUser();
$form->data['user_id'] = $user->id;
?>

Again nothing happened.

Can anyone help me? I can't help thinking there is some basic gap in my coding knowledge which all you guys are keeping a closely guarded secret! Alternatively do I need to move my development site to my external host to get it to work properly?

Many thanks in advance
GreyHead 22 Oct, 2013
Hi fdaley,

Welcome to the wonderful and baffling world of PHP and similar stuff.

I was wondering how anyone would be expected to remember a 32 character token and why it would end up in a URL

They wouldn't but fortunately computers don't have any big problem with long numbers.

It's most likely that you will want to load a form with existing data from some other link or reference on your site. The cf_uid is one way to get a unique reference to the data you want to access. The current user ID is another, if the user is logged in and there is one record per user. The record id is another - but it's not very secure.

Personally I prefer to use shorter random strings of 6-8 characters that could be remembered if strictly necessary.

The User code you tried will only work if the user is logged in - if they are a guest then the User ID is 0. That should still show up though if you have {user_id} in, for example, a Thank You page action.

Bob
fdaley 22 Oct, 2013
Thanks for your swift reply which is really appreciated. I think I have sussed this out and, for test purposes have used as the DB Field cf_created_by which is the numerical field which can be joined to the id field of the users table (which I have called "usernumber" as the Request Param) and by adding "&usernumber=630" to the form's URL. I will tie it to something more secure when I get to the real site but, to ask another rather embarrassing question, which I am sure is obvious to everyone else, how do you tell your user's browser to put his numerical id field at the end of the form's URL?

By the way one of the things which confused me before is that in order to get this all to work you have to add it as a system link menu item rather than as a Chronoform item in the menu. I presume that's the right thing to do; it works anyway.
GreyHead 22 Oct, 2013
Hi fdaley,

You don't need them to add it to the URL. Joomla! knows what it is so you can look it up before you call the DB Record Loader. You just need to set an entry in the $form->data array (where ChronoForms keeps it's working record of the current form data) and put the name of that entry in the Request Param box.

So add a Custom Code action to your form, drag it before the DB Record Loader and add this code to it:
<?php
$user =& JFactory::getUser();
$form->data['user_id'] = $user->id;
?>
Now add user_id to the Request Param box.

Bob
fdaley 23 Oct, 2013
Many thanks for this. It works but if the user overwrites the information in the form with new information it doesn't seem to update the form but creates a new form entry in the database. Is that what should be happening?

Regards

Frances
This topic is locked and no more replies can be posted.