Skip to Content Skip to Menu

🕒 Save Time and Effort with CB Editor Assistant: Effortlessly create and refine content in Joomla 3, 4, & 5.
🎁 Limited Offer: Enjoy a 5-day FREE trial and save up to 30% afterward!

[SOLVED] Is there a "proper" way of adding to a user profile from a form?

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
12 years 2 months ago - 12 years 1 month ago #214942 by fribse2011
We have a website where users can register themselves, when they do that they give the usual info, username, email, fullname, password.
When they want to become members of our diving club, they are asked for at quite extensive set of information, which we then use to sign them up for the danish diving organization.
Currently they then have to enter the same information to their profile on the website.

Is there a 'proper' way of adding this info to their profile, I mean, I can do a SQL query and just push it into the table, but it seems kinda rough.
The form used for them to enter the info in, is Chronoforms, so there are quite a lot of possibilities to do stuff.

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 12 years 1 month ago by fribse2011.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
12 years 2 months ago #214984 by krileon
Yes, create an extension or CB component plugin that renders a form then does a POST to it self and passes that info to the users profile using CB API. You should never use direct queries unless you absolutely have to. Below is a tutorial on how to load in a user object.

www.allmysocials.com/directory/tutorials/item/232-establishing-user-object

Once you've $user you can change field values using $user->cb_field = 123 then store as needed with $user->store(). I've no idea if Chronoforms is capable of API usage like this however.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
12 years 1 month ago #215354 by fribse2011
With the help from the very nice Chronoforms developer, I found out how to put this in the chronoforms (custom code building block).
So I added this code:
Code:
<?php Global $_CB_framework; $myId = $_CB_framework->myId(); $user =& CBuser::getUserDataInstance( $myId ); $user->name = $form->data['navn1']; $user->cb_cell = $form->data['mobil1']; $user->cb_adresse = $form->data['adresse1']; $user->cb_postnummer = $form->data['post1']; $user->cb_birthday = $form->data['foedsel1']; $user->store(); ?>
But when doing that I get an error like this:
Fatal error: Call to undefined method JUser::store() in /administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 8

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
12 years 1 month ago #215458 by krileon
You need to include the CB API first before you can use it. Please see the below tutorial on how to do this.

www.allmysocials.com/directory/tutorials/item/231-include-api-externally


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: fribse2011

Please Log in or Create an account to join the conversation.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
12 years 1 month ago - 12 years 1 month ago #215461 by fribse2011
Ahaaa, THANKYOU!
Now it seems to work properly, GRRRREAT, that's going to save my users some time when they sign up to the diving club.
Now I need to idiot proof it a bit :-D But that's another story.
The code ended up looking like this:
Code:
<?php global $_CB_framework, $mainframe; if ( defined( 'JPATH_ADMINISTRATOR' ) ) { if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) { echo 'CB not installed!'; return; } include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ); } else { if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) { echo 'CB not installed!'; return; } include_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ); } $myId = $_CB_framework->myId(); $user =& CBuser::getUserDataInstance( $myId ); $user->name = $form->data['navn1']; $user->cb_cell = $form->data['mobil1']; $user->cb_adresse = $form->data['adresse1']; $user->cb_postnummer = $form->data['post1']; $user->cb_birthday = $form->data['foedsel1']; $user->store(); ?>

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.
Last edit: 12 years 1 month ago by fribse2011.

Please Log in or Create an account to join the conversation.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
12 years 1 month ago #215473 by fribse2011
I just had a thought, as this is a 'dangerous' thing to do, I want to make sure that it's done right.
If another user is logged in when they confirm their signup, then it's that other user that will be updated.
My thought is to compare the currently logged in user's email address with the email address given in the form
Something like this
Code:
if ($juser->email == $form->data['email1']) { $user->name = $form->data['navn1']; $user->cb_cell = $form->data['mobil1']; $user->cb_adresse = $form->data['adresse1']; $user->cb_postnummer = $form->data['post1']; $user->cb_birthday = $form->data['foedsel1']; $user->store(); };

Or maybe via CB:
Code:
if ($cbUser->getField( 'email', null, 'html', 'none', 'profile' ) == $form->data['email1']) {

Neither of these seems to be 'true' and perform the update.

Best regards
Fribse

Frømandsklubben Nikon, www.nikondyk.dk
We're a volunteer driven diving club in Ishøj, Denmark.
Har du brug for en dykkerklub der rummer alle, så kom ned til os.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum