Forums

Fields added to registration but not saved in database

kevinash 10 Dec, 2009
Hi everybody,

I've a little problem, probably common but I don't find the solution.

I've followed the CF tutorial to build a joomla registration form using Chronoforms and I've added some fields to add the address of the user. I've also added the corresponding fields to the jos_users table.
I met no problem to create the form but when I try the form, none of my added fields are saved in database.
Does someone have a solution ?

I found a hack to modify the joomla registration form but it's not usable in this case because I want to use Chronoforms.

Thank you in advance for your help.

Kevin
GreyHead 10 Dec, 2009
Hi Kevin,

I strongly recommend that you do *not* modify the jos_users table. It may cause you significant problems with future upgrades. Instead use a separate table and linkthe two with the user_id.

I think the immediate problem is because the Registration plugin uses the Joomla code to 'do' the registration and this know nothing about your extra fields. You could hack the core code to work round this, or hand code an UPDATE to the jos_users record to run after the registration. If I remember correctly the plugin has an Extra Code after box where you could do this.

Bob
kevinash 10 Dec, 2009
Hi Bob,

Thanks for your quick reply!
OK, I find it's a good idea to hand code an UPDATE to the jos_users record to run after the registration.
But how can I get the user id (in the Extra Code after box)? Because at that moment the user has just received the email with the validation link but he's not logged. (So I can't call JFactory::getUser() to get the id, I'm right ? )
Do you have any idea ?

Thanks a lot.

Kevin
GreyHead 10 Dec, 2009
Hi Kevin,

Joomla updates the User object in the registration process so you should be able to get the new user_id from JFactory::getUser()

Bob
kevinash 10 Dec, 2009
Hi Bob,

Thank you, I'm going to try this way.

Kevin
nml375 10 Dec, 2009
Hi Kevin,
The Joomla Registration plugin will provide a reference to the newly created JUser object, which among other things, contain the user id. Something like this should do the trick:
<?
$MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id);
$user =& $MyPlugins['user'];
/* new user id available as $user->id */
...


Be adviced though, that neither your JUser nor JTableUser matches the jos_users database table if you continue with your plans of augmenting your jos_users table. This will cause serious problems if any of your extra fields have the property NOT NULL and no default value.
I would actually strongly recommend that you patch your JUser and JTableUser classes to match your new jos_users table, if you intend to continue along this path. Keep in mind that you would most likely have to redo this every time you update your Joomla installation.

/Fredrik
kevinash 11 Dec, 2009
Hi Fredrik,

Thank you for this useful code but at this moment I have trouble with the code I wrote in the "Extra after onsubmit " box.
I try to insert data into a dummy table to see if my code after the onsubmit works fine but nothing is saved !
When I register a new user, the dummy table aren't updated...

Here is the code I put in the extra after onsubmit box :
<?php
$db =& JFactory::getDBO();
$insert = "INSERT INTO dummy_table (uid,recordtime,ipaddress,cf_user_id,email,nouveau)
  VALUES ('','11/12/2009','','99','kevin@mail.com','');";
$db->setQuery($insert);
if(!$db->query()){
  echo $db->stderr();
}
?>

(The user is well registered).

Did I do something wrong ? Why the extra after onsubmit code isn't executed ?

Thanks for your help and your advices.

Kevin
GreyHead 11 Dec, 2009
Hi Kevin,

Where are you putting this code exactly?

Is it the 'Extra after Registration code' box in the Plugin setup?

Or one of the Extra Code boxes on the Form Code tab (they don't execute automatically).

Bob
kevinash 11 Dec, 2009
Hi Bob,

In the forms manager I tick my form then I click on "Joomla Registration" and then I put the code in the "Extra after onsubmit code" box.
This code is not executed automatically ?

Thanks

Kevin
GreyHead 11 Dec, 2009
Hi Kevin,

My version of the plugin has a different description for the After Code boxes. The code is executed for me, I don't know about your version.

Bob
kevinash 11 Dec, 2009
Bob,

I use the version 1.5.9 of Joomla! and the version V3.1 RC2 of ChronoForms.
Does that help you to figure out why it doesn't work for me ?
Is it possible to update only the Joomla Registration plugin without updating the complete ChronoForms ? (Because my version of CF works very well and I don't want to take the risk of losing all my forms if I do the update wrongly).

Kevin
GreyHead 11 Dec, 2009
Hi Kevin,

Try these attached files. Rename the old versions so that you can revert if they don't work.

unzip then FTP the files into the following locations

administrator\components\com_chronocontact\helpers\plugin.php
components\com_chronocontact\plugins\cf_joomla_registration.php

The updated helper may cause problems with older versions of other plugins :-(

Bob

PS Updating from RC2 shouldn't be a problem.
kevinash 11 Dec, 2009
Hi Bob,

Thanks a lot !
I'll try this asap!

Kevin
kevinash 11 Dec, 2009
Bob,

There is only one file (cf_joomla_registration.php) into the zip file... No plugin.php.

Kevin
GreyHead 11 Dec, 2009
i Kevin,

Sorry, added to the previous post.

Bob
kevinash 11 Dec, 2009
Thanks Bob.

I've tried but it doesn't work.
Now even the registration doesn't work !

I put the code into the "Extra after Registration code" box into the "Extra code" tab.
I have 5 error messages now in the Joomla Registration Plugin :

Notice: Undefined property: extra6 in c:\program files\easyphp1-8\www\sitejoomla2\administrator\components\com_chronocontact\helpers\plugin.php on line 38 (and the same message for extra7, extra8, extra9 and extra10)



Is it because the helpers folder didn't exist before and I had to create it ?

Kevin
GreyHead 11 Dec, 2009
Hi Kevin,

Worth the try but switch back to the old versions please :-(

Bob
kevinash 11 Dec, 2009
Bob,

I've found !! Why didn't I think to try this before ??😲

I just have to enable data storage and choose my extra table and all the extra fields of my register form will be saved !! As easy as that !

Thanks anyway for all the time that you spent on my problem and all the help that you gave me !!

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