Skip to Content Skip to Menu

Change CB Query Field data on profile-edit and SQL update DB on save.

  • NFA
  • NFA
  • OFFLINE
  • Posts: 84
  • Thanks: 15
  • Karma: 0
1 year 6 months ago - 1 year 6 months ago #333503 by NFA
Hi,

Our GJ Group owners need to maintain extra group related data in tables from other Joomla extensions. It would be nice if they could do all their website changes at one place. So I am looking for a way that my GJ Group owners can check and change these group related values on their CB profile edit.

I don't want to store any kind of this data in any JoomlaPolis (CB and GJ) table. This because some CB users don't own any GJ Group, while there are also users owning 20+ groups. Besides that, group ownership can be changed at any moment by them after deleting their groups or handing over their ownership.

Showing and not saving these values on profile-edit is very easy with a CB Query Field. But how can I make these field values (temporary) editable in the profile-edit mode? So that on profile save (onBeforeUserProfileSaved), a CB Auto Action(s) can execute a SQL update to put the changed data value back in the (non-JoomlaPolis) table field where they reside.

Hope you can help me. It would be so great if users could change all their related personal and group data in their CB profile-edit mode, even when that data reside in tables from other Joomla extensions. For example, so that the sales targets of a group (which value is stored in a Joomla Sales Administration extension), can be changed by the GJ group owners when this manager is editing his/her CB Profile.

With kind regards,
Noa
Last edit: 1 year 6 months ago by NFA.

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

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 6 months ago #333509 by krileon
Create a Custom HTML field then add whatever inputs you want to it using standard HTML. Use onBeforeUserUpdate to apply any server side validation checks you may need. If it fails your validation use the below to throw an error and interrupt the save.
Code:
global $_PLUGINS; $_PLUGINS->_setErrorMSG( 'ERROR_MESSAGE_HERE' );

Next use onAfterUserUpdate to store your inputs. All of this you'll need to code yourself using PHP in a Code action. You'll need to access the inputs directly from POST, which you can do using substitutions if you like (e.g. [post_INPUTNAME]).


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.

  • NFA
  • NFA
  • OFFLINE
  • Posts: 84
  • Thanks: 15
  • Karma: 0
1 year 6 months ago #333515 by NFA
Thanks for your answer.

Okay, good point, I will try to use a Custom HTML field for the temporary display and edit option on profile-edit.

- But how do I insert the result of a SQL select in that Custom HTML field when onBeforeUserProfileEditDisplay is triggered?

You'll need to access the inputs directly from POST, which you can do using substitutions if you like (e.g. [post_INPUTNAME]).

What do you mean with that? Isn't there an easier way to grep the temporary input in that Custom HTML field and use that in a SQL update statement onAfterUserUpdate?

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

  • krileon
  • krileon
  • OFFLINE
  • Posts: 48419
  • Thanks: 8274
  • Karma: 1443
1 year 6 months ago - 1 year 6 months ago #333518 by krileon

 - But how do I insert the result of a SQL select in that Custom HTML field when onBeforeUserProfileEditDisplay is triggered?

You'd need to use a Code field in that case and supply whatever PHP you like to render your custom edit field.

What do you mean with that? Isn't there an easier way to grep the temporary input in that Custom HTML field and use that in a SQL update statement onAfterUserUpdate?

The easiest way to get the POST data for your custom inputs is to use substitutions. For example lets say I have a text field with name="group_name" then I can get that using [post_get_name]. So yes you could use a Query action if you wanted to here, but be sure to use format functions to sanitize the data. Example as follows.
Code:
UPDATE `#__mytable` SET `group_name` = '[cb:parse function="clean" method="string"][pst_group_name][/cb:parse]' WHERE `owner` = '[user_id]'

Notice the clean format function. This will sanitize it to a string. SQL quotes will automatically be escaped so you shouldn't need to deal with those.


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.
Last edit: 1 year 6 months ago by krileon.
The following user(s) said Thank You: NFA

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

Moderators: beatnantkrileon
Powered by Kunena Forum