[list](1) How to save values of extra fields in the database?[/list]
[list](2) How to customize or make new form to let user update their profiles as per the complete registration form?[/list]
Details of my form fields are given below:
Joomla's Default fields for registration:
First Name -> 'Name' field name
E-mail -> 'Email' field name
Username -> 'Username' field name
Password -> 'Password' field name
Confirm Password -> 'Confirm password' field name
Extra fields added by me:
Last Name
Date of Birth
Specialty
If Others, please specify
Date of Graduation
Date of Post Graduation
Work Address
Home Address
Mobile Phone
Subscribe to Email (shouldn't this field be mapped to sendEmail field in jos_users table ??)
Thanks.
Have you created a table to save the extra data? If not, please see the Database Tutorial from the Tutorials link above.
Bob
Yes, table is created having "id" as int(11) and is a primary field.
Do I need ChronoConnect to achieve my goal?
Related to my questions, I need your guidance for;
(1) what query it should be and where it should be placed to add a record in that extra table?
(2) as a rule, form should be accessible only for registered users therefore right there when form displays, making this link is not a problem but profile updation form should display existing values in respective fields for updation.
Q.3: Is it possible to have one form to update Joomla's default values plus these additional fields simultaneously? If yes then how?
Q.4: What should be my strategy to manage user records when one or more users gets deleted by Joomla's user manager? If corresponding records in this extra table should also be deleted then how do we link this deletion process with Joomla's user manager?
Am I asking too much?
Its been whole night and day now while searching this forum to get my queries answered but may be I am out luck because I dont seem to get my hands on answer so far.
Thanks.
Can we leave Q.3 & 4 for now and continue with my original query?
Thanks.
Q.3: Yes, create a form that uses the DB connection to update the 'extra' table. And add some code to repiicate the Edit Account details form for the jos_users columns - I think you just need to update and save the Joomla User object,
Q.4: Never seen this question before. I'd guess that the simplest answer is to create an admin only housekeeping form that will run a check and delete any records for users who are no longer in the user table. You could link this to a cron job if you like and run it once a week. I'm sure that you could dig into the core code and link to the delete function but I think it would require a core hack.
Bob
Thanks for your inputs on my queries 3 & 4.
Purpose of site I am working on is to provide latest information for different types of cancers and developments for treatment. User section is for Doctors only so that they can participate in discussions, communicate and discuss case studies etc. for free.
Now, regarding my original query:
I have an extra table "jos_chrono_user_profile" which has following extra fields:
id - int(11), it is a primary field
Last Name :: 'extraLName' - varchar(30)
Date of Birth :: 'extraDOB' - date
Specialty :: 'extraSpecialty' - varchar(30)
If Others, please specify :: 'extraSpecialtyOth' - varchar(30)
Date of Graduation :: 'extraDtGrad' - date
Date of Post Graduation :: 'extraDtPG' - date
Work Address :: 'extraWAddr' - varchar(100)
Home Address :: 'extraHAddr' - varchar(100)
Mobile Phone :: 'extraMobile' - varchar(30)
Subscribe to Email :: 'extraEmailSub' - tinyint(1)
Purpose of my form is that once a visitor submits registration form, a new record should also be added as per above fields having 'id' of currently record added in 'jos_users' table, so that later on I can link this record with the record in 'jos_users' table e.g. to update these extra fields by user themselves.
Now, my question to the point is:
What will be the code to add a record in that extra table and where it should be placed (e.g. On Submit code - before sending email etc.)?
Thanks.
If you are using the ChronoForms 'Joomla Registration Plugin' then you don't need to add this code anywhere. Set up the DB Connection Tab to link to this table and ChronoForms will save it for you provided that the input field names match the DB table column names.
Bob
Thank you for helping me, now the extra fields are being saved in separate table "jos_chrono_user_profile". 🙂
This extra table has following fields created by ChronoForm itself:
cf_id => int(11) - Primary Key, auto_increment
uid, recordtime, ipaddress, cf_user_id => all VARCHAR(255)
One small issue for letting user edit/update their registration information after login. I have created another form which has all fields minus basic joomla registration fields and used Profile plugin to let user edit / update their details. It loads and show data correctly but saving them creates a new record instead of updating the existing one (as per cf_user_id which has the correct id as per jos_users table).
Please guide me on what do I have to do to enable form to update existing user's detail by logged in users themselves?
Thanks.
This worked alright and records were getting updated, Until, by using Wizard option I deleted one checkbox field and added RadioButton instead (as I wanted selection Y for Yes and N for No). Since this change, old problem came back in which every attempt to update user profile by a registered user is creating a new record instead of updating the existing one.
A screenshot of duplicate record creation is also attached.
[attachment=0]chrono-duplicate-record.gif[/attachment]
In the above result when cf_user_id and cf_id is same (i.e. 63) then while updating record by a user having id/cf_user_id as 63 how another record being created instead of updating the one having cf_id = 63?
I also tried the code given below at On Submit code - before sending email but no change in the result:
$db &= JFactory::getDBO(); /* Retrieve the database object */
$user &= JFactory::getUser(); /* retrieve user object, this is for user id */
JRequest::setVar('cf_id', $user->id, 'post');
Can you help me Bob?
Thanks.
I've lost track of what you are trying to achieve here.
The cf_id is the unique record identifier *for this table* - clearly in some tables the same user may make many entries so it can't be the same as the user_id.
The cf_user_id is the Joomla User ID of the current user.
It is possible to have these two identical but needs careful work to synchronise them from the beginning. One way is to alter the table that the user_cf_id field is the primary key (and possibly to remove the cf_id field).
Another way is to look up the cf_id value with a MySQL query either in the Form HTML or in the OnSubmit Before box and to set the corresponding value using JRequest::setVar().
Which is best for you really depends on the details of your implementation.
Bob
To summerize my purpose and what I did:
I created a form using CF which has extra fields to use in Joomla Registration. This is working fine and details are being added in jos_users as well as extra table created by ChronoForm (by selecting form and clicking on Create Table). This part is over and working well.
Next comes to let user update their profile in extra field. For this, I created another form and used Profile plugin and DB connection to the same extra table which is also linked to first form for joomla user registration. This form only has those extra fields to be updated.
In this Forum at http://www.chronoengine.com/forums.html?cont=posts&f=2&t=15342&start=0&hilit=update+record
It is mentioned that as long as the primary field (cf_id here) is same as of id of logged in user then ChronoForm will attempt to perform an update while writing a record and if not then the record will be added. This is the reason I had set AUTO_INCREMENT value cf_id to match with id of jos_users. Please correct me if I understood wrong.
Now coming back, to your last comment:
The cf_id is the unique record identifier *for this table* - clearly in some tables the same user may make many entries so it can't be the same as the user_id.
This is in contradiction to what I had read in another post as mentioned above.
All I want is to update a single record which is actually a profile record so there will only be one such record in that extra table.
Now, coming to the options you have mentioned:
One way is to alter the table that the user_cf_id field is the primary key (and possibly to remove the cf_id field).
I altered the extra table by:
a) removed cf_id field
b) made cf_user_id as primary int(11)
After I did this, an attempt to update that record is giving following error:
[attachment=0]chronoform_error_in_update.gif[/attachment]
The error above indicates that ChronoForm is attempting to add a record instead of performing update on an existing record.
Bob, please let me know if some thing is not clear.
Awaiting your reply.
Thanks.
I'm still pretty confused.
It is mentioned that as long as the primary field (cf_id here) is same as of id of logged in user then ChronoForm will attempt to perform an update while writing a record and if not then the record will be added.
I had a quick looka dn don't see that in the thread, but I may have missed it.ChronoForms doesn't have any idea about the id of the logged in user. It only knows about field names and values. If you save a form where the value of a field with the same name as the primary key matches an exisiting record then it will try to update the record instead of adding a new one.
I have missed one problem here that Fredrik talks about in the other thread. You probably can't autoincrement the field with the User id - it always has to be set externally to match the Joomla user id. If your table needs an autoincremented index then you need to keep the old cf_id and look up the vlaue corresponding to the current user id before you save.
I suspect that the duplicate field error is because you have kept old records in the table??
Bob
PS We'll do our best to help you here but it really isn't possible to give more than a few minutes to each post and you are into some quite deep technical issues here.
I understand how busy you are and respect your willingness to help.
I will try to be more precise and short here to give you more time to concentrate on solution instead of problem. 🙂
The table "jos_chronoforms_registerextform" has records related to every users' profile therefore, for one user there has to be one record. I created a form and enabled only Profile plugin, then connected it with that table, set "Edit" to yes. The form, when accessed by logged in user, shows that user's record but submitting this form for the purpose of updating users profile, a new record is created instead with all values of form.
Now my problem is, what do I do to make this form update that record instead of adding?
Thanks.
First of all, my problem is solved. 😀
Everything I had done so far after following your guidelines were correct and what I was doing wrong is that after deleting cf_id from that extra table, I forgot to link cf_user_id with the table at "Configure Profile Table plugin" page, where "Target field name" was showing as "--?--" because I had deleted the earlier linked field "cf_id" -- my mistake 🙄
Now respective user's profile record is being updated nicely on submit the form.
Thank you and hats off to you Bob, for being patient and helping me through the thick of my problems and mistakes.
Could you please tell me the purpose and significance of "checkToken" ON/OFF ?
Thanks.
I'm delighted that it's working - well done.
The security token is a random string that is saved in the user session when a from is loaded and checked when it is submitted to make sure that the same session is submitting the form as opened it. There is a small security risk of sessions being high-jacked. (This was added in Joomla 1.5.6 or thereabouts - more info in the Joomla security blog I think.) If it works on your site then better to leave it on. If you have problems with users seeing error messages then try turning it off.
The security risk is real but probably vanishingly small for most sites unless you are very popular or a possible target.
Bob
So, I have fixed it that I can do the registration with chronoforms. That works fine.
Now, all users are in jos_users.
Then I want that users add some more fields. I use another table jos_chronoforms_members and use the plugin 'Profile Page'
The jos_chronoforms_members table use 1 hidden field cf_user_id, and have actualy 1 extra field.
I deleted the cf_id via phpmyadmin and put the cf_user_id as int(11) and primlary key.
I know that now it is only possible to add one record with the same user_id.
In Profile Page Plugin, I put the next changes
- Table name : jos_users
- Target Field : ID (via drop down)
- Request parameter : cf_user_id
- editable : yes
I needed to add the follow line in my code, to be sure that the the user_id is filled in
<?php
$user =& JFactory::getUser();
echo '<input type="hidden" name="cf_user_id" value="' . $user->id . '" />';
?>
But... if I put now something in my extra field, and after submit, I get the error 'duplicate entry'
What do I wrong ?
This is caused by the default behaviour of the JTable classes. Roughly put, it tries to be smart as to whether an INSERT or UPDATE should be done. This works well-enough for auto_increment Primary Keys, but not so well for Primary Keys with user-specified values.
I think I still have some modified code that should do the trick on my workstation at home, I'll see about finding that piece'o'code once I get to home...
There was also a thread here on the forum with a similar issue, but different approach: The cf_id field remains primary key, and instead some code was used to find a user's record, and set cf_id to this.. I'll see about finding that code as well.
/Fredrik
I was unable to find the code for the modified JTable. However, I do have code for the second approach I mentioned.
Prerequisites:
Form with proper DB Connection with jos_chronoforms_members.
Table jos_chronoforms_members with:
- cf_id primary key (auto_increment)
- cf_user_id contains User ID.
Send email enabled on the General Tab. This is required to enable the "on Submit - before email" control. You do not need to add or enable any email setups however.
The code (enter in "on submit - before email"):
<?
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$query = sprintf('SELECT %s FROM %s WHERE %s = %d LIMIT 1',
$db->nameQuote('cf_id'),
$db->nameQuote('#__chronoforms_members'),
$db->nameQuote('cf_user_id'),
$user->id
);
$db->setQuery($query);
$result = $db->loadResult();
JRequest::setVar('cf_id', $result ? $result : 0);
?>
/Fredrik