Hi,
I use the 'Joomla User Registration' event (after onSubmit) in my form to make a registration form.
In the 'OnSucces' event of the registration-event I also save the data (with a 'DB Save' action) into a chronoform-db because I have some customer fields at registration.
So far, all works well. After succesfull registration of the user, and succesfull saving of the data in the chronoform-db, the user in the Joomla user DB has got an 'id' with a value, but the field 'cf_user_id' in the chronoform-db has value 0. I would like to save this 'id'-value also in the field 'cf_user_id' in the chronoform-db so I have to update the chronoform-DB after registration.
To do this I put in a 'Custom Code' action, just after the 'DB save' action. In this 'Custom Code' action I have the following code:
Somehow this does not work beacause the 'cf_user_id' field is not being updated after succesfull registration of the new user.
What am I doing wrong or what is alternative method to update the DB?
Robin
I use the 'Joomla User Registration' event (after onSubmit) in my form to make a registration form.
In the 'OnSucces' event of the registration-event I also save the data (with a 'DB Save' action) into a chronoform-db because I have some customer fields at registration.
So far, all works well. After succesfull registration of the user, and succesfull saving of the data in the chronoform-db, the user in the Joomla user DB has got an 'id' with a value, but the field 'cf_user_id' in the chronoform-db has value 0. I would like to save this 'id'-value also in the field 'cf_user_id' in the chronoform-db so I have to update the chronoform-DB after registration.
To do this I put in a 'Custom Code' action, just after the 'DB save' action. In this 'Custom Code' action I have the following code:
<?php
$id = $form->data['id']; /*the user id of the new user after succesfull registration */
$naam = $form->data['naam']; /*the user name*/
/* update the chronoform-db with the new value of cf_user_id */
$db =& JFactory::getDBO();
$query = "
UPDATE `#__chronoforms_projector_bedrijven`
SET
`cf_user_id` = {$id}
WHERE `naam` = {$naam};
";
$db->setQuery($query);
$db->query();
?>Somehow this does not work beacause the 'cf_user_id' field is not being updated after succesfull registration of the new user.
What am I doing wrong or what is alternative method to update the DB?
Robin
Hi rmesman,
If you want to save the user ID in the DB then the Custom code needs to go before the DB Save action.
Please see this FAQ
Bob
If you want to save the user ID in the DB then the Custom code needs to go before the DB Save action.
Please see this FAQ
Bob
Hi Bob,
In your example a user is already registred and logged in; then it is easy to retreive the user-id. In mine situation the user is only being registred; the user id is being created within the form execution process and the user is not logged in (yet). How then retrieve the user-id of the user that is being created by the form? Just put the 'Custom Code' before the 'DB Save' code?
When I debug the form this is all the info I see;
I see the array with info that is being processed and somewehere in middle, where is says [joomla_registration], I assume there the registration of user starts. The user-id [id] is the field I need after the registration-process to save into the DB.
If I do this before the 'custom code' action then I have only saved the 'id' to the field 'cf_user_id'. How then update this record with the other data?
Does it makes sense?
Robin
In your example a user is already registred and logged in; then it is easy to retreive the user-id. In mine situation the user is only being registred; the user id is being created within the form execution process and the user is not logged in (yet). How then retrieve the user-id of the user that is being created by the form? Just put the 'Custom Code' before the 'DB Save' code?
When I debug the form this is all the info I see;
Data Array:
Array
(
[chronoform] => projector_bedrijven
[event] => submit
[Itemid] => 510
[option] => com_chronoforms
[view] => form
[bedrijfsnaam] => MAD
[naam] => Robin Mesman
[gebruikersnaam] => rmesman
[email] => robin.mesman@gmail.com
[password] => *******
[password_confirm] => *******
[aantal_leden] => 0
[or_code] => 000000
[or_lid] => 0
[submit] => verstuur
[b866ad75ffe014fb9a0f77b243363001] => 1
[name] => Robin Mesman
[username] => rmesman
[password2] => *******
[_PLUGINS_] => Array
(
[joomla_registration] => Array
(
[*isRoot] =>
[id] => 46
[name] => Robin Mesman
[username] => rmesman
[email] => robin.mesman@gmail.com
[password] => *******
[password_clear] => *******
[usertype] => deprecated
[block] => 1
[sendEmail] => 0
[registerDate] => 2012-07-09 15:06:24
[lastvisitDate] =>
[activation] => bf2474c3d568a48757938c4eddd20d76
[groups] => Array
(
[0] => 13
)
[lastResetTime] =>
[resetCount] =>
[*_params] => JRegistry Object
(
[data:protected] => stdClass Object
(
)
)
[*_authGroups] => Array
(
[0] => 1
)
[*_authLevels] => Array
(
[0] => 1
[1] => 1
)
[*_authActions] =>
[*_errorMsg] =>
[*_errors] => Array
(
)
[aid] => 0
[chronoform] => projector_bedrijven
[event] => submit
[Itemid] => 510
[option] => com_chronoforms
[view] => form
[bedrijfsnaam] => MAD
[naam] => Robin Mesman
[gebruikersnaam] => rmesman
[password_confirm] => *******
[aantal_leden] => 0
[or_code] => 000000
[or_lid] => 0
[submit] => verstuur
[b866ad75ffe014fb9a0f77b243363001] => 1
[password2] => *******
)
)
[chronoform_data] => Array
(
[cf_uid] => f278316d030f0408f9c40394158e73ed
[cf_created] => 2012-07-09 17:06:25
[cf_ipaddress] => *******
[cf_user_id] => 0
[chronoform] => projector_bedrijven
[event] => submit
[Itemid] => 510
[option] => com_chronoforms
[view] => form
[bedrijfsnaam] => MAD
[naam] => Robin Mesman
[gebruikersnaam] => rmesman
[email] => robin.mesman@gmail.com
[password] => *******
[password_confirm] => *******
[aantal_leden] => 0
[or_code] => 000000
[or_lid] => 0
[submit] => verstuur
[b866ad75ffe014fb9a0f77b243363001] => 1
[name] => Robin Mesman
[username] => rmesman
[password2] => *******
[_PLUGINS_] => Array
(
[joomla_registration] => Array
(
[*isRoot] =>
[id] => 46
[name] => Robin Mesman
[username] => rmesman
[email] => robin.mesman@gmail.com
[password] => *******
[password_clear] => *******
[usertype] => deprecated
[block] => 1
[sendEmail] => 0
[registerDate] => 2012-07-09 15:06:24
[lastvisitDate] =>
[activation] => bf2474c3d568a48757938c4eddd20d76
[groups] => Array
(
[0] => 13
)
[lastResetTime] =>
[resetCount] =>
[*_params] => JRegistry Object
(
[data:protected] => stdClass Object
(
)
)
[*_authGroups] => Array
(
[0] => 1
)
[*_authLevels] => Array
(
[0] => 1
[1] => 1
)
[*_authActions] =>
[*_errorMsg] =>
[*_errors] => Array
(
)
[aid] => 0
[chronoform] => projector_bedrijven
[event] => submit
[Itemid] => 510
[option] => com_chronoforms
[view] => form
[bedrijfsnaam] => MAD
[naam] => Robin Mesman
[gebruikersnaam] => rmesman
[password_confirm] => *******
[aantal_leden] => 0
[or_code] => 000000
[or_lid] => 0
[submit] => verstuur
[b866ad75ffe014fb9a0f77b243363001] => 1
[password2] => *******
)
)
[cf_id] => 1
)
[chronoform_data_cf_id] => 1
)
Validation Errors:
Array
(
)I see the array with info that is being processed and somewehere in middle, where is says [joomla_registration], I assume there the registration of user starts. The user-id [id] is the field I need after the registration-process to save into the DB.
If I do this before the 'custom code' action then I have only saved the 'id' to the field 'cf_user_id'. How then update this record with the other data?
Does it makes sense?
Robin
Hi rmesman,
Sorry, I've updated the FAQ to add a section on getting the ID of a newly registered user.
Bob
Sorry, I've updated the FAQ to add a section on getting the ID of a newly registered user.
Bob
Actually tested it but still something is wrong. Using the Custom code (for testing):
Results in:
So, a little bit of tuning is needed...
$id = $form->data['_PLUGINS_']['joomla_registration']->id;
echo "user id:".$id;Results in:
user id:Data Array: So, a little bit of tuning is needed...
Found the solution. The testing Custom code needs to be:
So, to have the newly created user-id saved for further purposes the Custom Code is:
If I put a DB Save action after the Custom Code then the field 'cf_user_id' is being saved with the value of the just created user-id.
But I can also use it in emails with {cf_user_id}
$id = $form->data['_PLUGINS_']['joomla_registration']['id'];So, to have the newly created user-id saved for further purposes the Custom Code is:
$form->data['cf_user_id'] = $form->data['_PLUGINS_']['joomla_registration']['id'];If I put a DB Save action after the Custom Code then the field 'cf_user_id' is being saved with the value of the just created user-id.
But I can also use it in emails with {cf_user_id}
Hello,
i want to make a DB Update query after data is submited by chronoform and after data was write to database by the Action. But i can't get it work. It's not possible to do this after the DB Save Action?
here my code:
<?php
$vuid=$form->data['formuid'];
echo $vuid;
$database =& JFactory::getDBO();
$query = "UPDATE #__chronoforms_data_rag SET ragz='0' WHERE formuid=$vuid";
$database->query();
?>
Have someone an idea🤨
i want to make a DB Update query after data is submited by chronoform and after data was write to database by the Action. But i can't get it work. It's not possible to do this after the DB Save Action?
here my code:
<?php
$vuid=$form->data['formuid'];
echo $vuid;
$database =& JFactory::getDBO();
$query = "UPDATE #__chronoforms_data_rag SET ragz='0' WHERE formuid=$vuid";
$database->query();
?>
Have someone an idea🤨
Solved, this code works for me!
<?php
$database =& JFactory::getDBO();
$sql = "
UPDATE #__chronoforms_data_rag
SET ragz = 'xxx'
WHERE formuid = '".$_POST['formuid']."';";
$database->setQuery( $sql );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>";
}
?>
<?php
$database =& JFactory::getDBO();
$sql = "
UPDATE #__chronoforms_data_rag
SET ragz = 'xxx'
WHERE formuid = '".$_POST['formuid']."';";
$database->setQuery( $sql );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>";
}
?>
This topic is locked and no more replies can be posted.
