How do I call a CF form for editing recorded data.

Skiverens 25 May, 2010
I know how to do it in use of Connectivity, but all I need is to know how Connectivity call the CF form with parameters about the selected record.
I call a Chonectivity document whit a selected record number in a SESSION. I want to edit the desired record with the original CF Form
What do I do?
nml375 25 May, 2010
Hi,
Have a look at the profile CFplugin. This is what ChronoConnectivity uses for editing as well.

You might have to use a trick or two if you'd like to retrieve the tablerow id from the session storage, as the plugin checks for a GET-style form field value for this;
fetch the value from the session storage in the usual way, and the use JRequest::setVar('uid', the_value, 'get') to set the form field value. Then tell the plugin that the row id is in uid, and enable form code execution.
Also, remember to set the form as editable in the plugin.

/Fredrik
Skiverens 25 May, 2010
Hi
I'm just a beginner in php and joomla and I do not know what the usual way is to fetch the value og a session. Is it a copy of the url? I have looked at CFplugin and recognized that this will enable the possibility to do the trick. But... could you make it easier for me to understand.
nml375 25 May, 2010
Hi,
Reading a value from the Session storage involves getting an instance of the JSession object, and calling the get() method of that instance. The parameters for that method is the name of the value, an optional default value (in case the requested value is not set in the current session), and an optional namespace identifier (used to avoid name collisions).

I might have mis-understood your initial question however. ChronoConnectivity does not use the session storage for retrieving the desired row identifier, but creates a custom plugin setup on-the-fly containing the row id value.

The normal behaviour with the Profile plugin is to see if you set a form field name (in the plugin setup). If so, and if that form field is supplied with a value, this is used to select the row from the database;
Lets say we set the "'Request' parameter name" setting to "uid". The url for loading row "beta" would then be: http://www.example.com/myformurl?uid=beta

If the user did not provide the uid=beta part, or you did not set a value for the setting, the plugin then moves on and checks the value of "Default Request Parameter value", and uses this for loading the row. This is what ChronoConnectivity uses, as it creates a custom plugin configuration on-the-run.

Lastly, if the default value is not set either, the plugin will fall back with the user id of the currently logged on user (has been known to cause issues with "new record" in CC when the user id matches a database row).

Soo... let's get working..
First off, from where do you wish to retrieve the value used to load the right row from the database?

/Fredrik
Skiverens 26 May, 2010
I tried but…
How do I call a CF form for editing recorded data. image 1
I configured plugin and defined target row to ID and RPN to uid. uid is just a alias, right?
My ChronoForm is named APV and the link is: http://www.skiverens.dk/index.php?option=com_chronocontact&chronoformname=PAV
I tried to make an CC and grapped the {edit recoed} link http://www.skiverens.dk/index.php?option=com_chronoconnectivity&connectionname=ret_PAV&task=editrecord&cids=$id'
$id represents the value “2”.
But this gave me this error: “You are not authorized to view this page, Row Edit Error”
I hope you will show me how to do it the right way.
nml375 26 May, 2010
Hi,
Sorry, but I'm having a hard time trying to figure what you are actually trying to achieve.

If you intend to use the ChronoConnectivity component, there's no need to setup the Profile CFPlugin in your form, as CC will do this on-the-fly.

The CC-link you posted should not contain $id, but the actual value (in your case, 2). The links on the CC-page seem ok, and loads the page without an error. There seem, however, to be no data entered in any of the database records.

The "Row Edit Error" message is because you are trying to enter the url directly, rather than load the CC list and click the link from there (as far as I understand, it's a security implementation which prevents you from editing any records you've not explicitly seen an edit-link for).

/Fredrik
Skiverens 26 May, 2010
IH
I'm sorry not to explain very well.
The setup is:
A user of my site will in a form of type password and after approval, get access to fill out a questionnaire form called APV. The point is. If he do not finish all questions, it will be possible to continue later.
So… In the password-form I Insert a row in the database table #__chronoforms_APV_std_data. Select the row and call the CC to continue answering the questionnaire.
That is the reason for use of CC with the edit facility.
I hope it get it more easy to understand.
I suppose you could use this link to my Chonoform: http://www.skiverens.dk/index.php?option=com_chronocontact&chronoformname=APV
If I use this direct link to my CC “ret_APV”: http://www.skiverens.dk/index.php?option=com_chronoconnectivity&connectionname=ret_APV&task=editrecord&cids=2
I get the security problem: “You are not authorized to view this page, Row Edit Error”
If I just open the CC in my back_end. The link will work correctly.
Will it be possible for me to use my Chronoform APV to edit the data in my table or do I need to use CC?
nml375 26 May, 2010
Hi,
Ahh, now I understand what you are trying to do here.
The downside; you cannot use ChronoConnectivity for this.
The upside; this shouldn't be too hard to achieve with ChronoForms and the Profile CFPlugin.

I'll assume your users can only fill out the form once; that is, whenever they re-submit the form, they actually edit the data from the earlier submissions..

The first order of business, make sure we got the proper fields in the database table:
ChronoForm uses 5 additional fields in the database table if they're present: cf_id, uid, recordtime, ipaddress, and cf_user_id. We'll atleast need the cf_user_id one, which will contain the userid of the person submitting the data (so that we can load the right data for the right user).

Next step, configure our profile cfplugin:
Table name: #__chronoforms_APV_std_data
Target field name: cf_user_id
Request Parameter name:
Default Request Parameter value:
Editable: Yes
Evaluate code: No

As you see, we leave both the request parameter name and default value empty. This is intended, and will cause the profile cfplugin to use the currently logged on user's id instead.

Last step, open the form setup, switch to the DB Connection tab and create a connection with #__chronoforms_APV_std_data, switch to the Plugins tab, and enable (red cross on a green bar) the Profile plugin. Save form.

/Fredrik
Skiverens 26 May, 2010
HI
Well, I know this very well.
The fact is that the user does not have to be registered. A public user gets a password from me on an e-mail.
When the user log in with the password, it will insert a temporary user_id in the #__chronoforms_APV_std_data. A select query find the actual id of the row.
Now it shall be possible to edit the row with this specified user_id.
The case is that the user shall be anonymous. So after finishing the questionnaire, the user_id will be overwritten and no one knows more than, it was one who has the password.
If the user will complete the questions at once, it would be much easier. Then I just could use the Chronoform APV without re-submit the form.
How do I make the re-submit of the APV form?
nml375 26 May, 2010
Hi,
In that case, choose a name for the "Request Parameter name". Either add this as an URL-style form field value, such as http://www.skiverens.dk/index.php=option=com_chronocontact&chronoformname=APV&formfieldname=user_id where formfieldname is whatever you entered in the "Request Parameter name" setup, and user_id this user_id of the anonymous user.

If you can't embed it into the URL itself, use a piece of code like this to your form html code:
<?
JRequest::setVar('formfieldname', 'user_id');
?>

formfieldname is once again whatever you entered in the "Request Parameter name", and user_id whatever user_id you've already retrieved from some query(?).
In this case, also remember to set the "Evaluate code" setting to Yes, so that this code is executed before the profile cfplugin tries to read it.

Oh, one more thing; you'll need to include a form input for the primary key of the database table for the save-operation to update the record rather than creating a new one. Preferrably, this should be a hidden one:
<input type="hidden" name="cf_id" value="" />

Don't worry about the value, it should be updated by the profile cfplugin along with the other data.

/Fredrik
Skiverens 27 May, 2010
HI
I don’t know where the value of the row shall be entered?

First of all. I have added:
JRequest::setVar('formfieldname', 'id');
in my php code for the APV form, in fact “id” is “the primary key colum”, and after INSERT a reservation of the row by INSERT og a user_id, I make a SELECT quire of the user.id, id. so I know the key value “id” of the row.

You add “&formfieldname=user_id” to the url. How do I put on the value of id?
I have tried:
http://www.skiverens.dk/index.php=option=com_chronocontact&chronoformname=APV&formfieldname=2
http://www.skiverens.dk/index.php=option=com_chronocontact&chronoformname=APV?id=2
but without success.
GreyHead 27 May, 2010
Hi Skiverens,

A URL query string always starts with a ? and uses & to separate the parameters e.g.
. . . index.php?name1=value1&name2=value2 . . .


Bob
Skiverens 27 May, 2010
OH, yes, it has to be: http://www.skiverens.dk/index.php?option=com_chronocontact&chronoformname=APV&uid=2
Now this will open the the ChronoForm APV, but it create a new record every time…
I have now configured profile in cfplugin:
Table name: #__chronoforms_APV_std_data
Target field name: cf_id
Request Parameter name: uid
Default Request Parameter value:
Editable: Yes
Evaluate code: Yes
By the way. The table in the database #__chronoforms_APV_std_data is not created with the ChronoForm Manager but by my own php code
I have now changed my id-colum to cf_id, but with the same result.
You are welcome to try yourself by use of the link.
nml375 27 May, 2010
Hi,
Did you remember to add the hidden input I mentioned in my previous post? (Can't view the HTML source right now, as I'm mobile using Opera Mini at the moment).

/Fredrik
Skiverens 27 May, 2010
Yes, and I get data in: cf_id, uid, recordtime, ipaddress and cf_user_id. But it is not row with cf_id=2, but a new record
nml375 27 May, 2010
Hi again,
I've had some time to check the linked form now. From what I can tell, no values what so ever are restored from the database into the form, including the cf_id primary key. This suggests that the plugin most likely is not enabled.

/Fredrik
Skiverens 27 May, 2010
Well I misunderstood your explanation about to flip over red to green under plugins. I thought it was in creating the table you wrote about.
Now it’s working....

I really appreciate your patience. Can I do something for you?
nml375 27 May, 2010
Hi,
If there is no value for any given input (or rather, empty value) in the database, that input will be empty or unchecked. If the yes/no radiobuttons are checked, then there is a value for that input in the database already.

/Fredrik
Skiverens 27 May, 2010
Thank you for help.
How do I close this topic?
This topic is locked and no more replies can be posted.