Skip to Content Skip to Menu

[SOLVED] Creating a user from a form

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
7 years 9 months ago #290092 by krileon
Replied by krileon on topic Creating a user from a form
That does create a new object. Please, stop trying to simplify the code before it's working. Follow the tutorials exactly then modify it after the fact. The alternative is to just fire a custom trigger and then act on it in CB Auto Actions to register a user. You can fire a custom trigger with the below.

Code:
global $_PLUGINS; if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! 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' ); cbimport( 'cb.html' ); $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'TRIGGER_NAME_HERE', array( TRIGGER_VARIABLES_HERE ) );

Your variables can be whatever you like. CB Auto Actions supports parsing for up to 10 variables. If you need more I suggest sending an object or array as 1 of the variables. Example as follows.

Code:
$_PLUGINS->trigger( 'custom_forceRegisterUser', array( $username, $name) );


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
7 years 9 months ago #290109 by fribse2011
Replied by fribse2011 on topic Creating a user from a form
Ok, ok, I will stop :-)

Looking at the example, there is a parameter in the function called $usergroups, but as far as I can see it isn't used at all in the given code?
And as I can see the 'gids' setting is calling the CB framework to get the standard 'new user group', so if the $usergroups is supposed to be ised, is that supposed to go into 'gids'?
And how am I supposed to give it in the call of the function if the users are to be part of a specific Joomla Group?
I'll create my form with the standard function for now, and then see if I can make it work.

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.

  • fribse2011
  • fribse2011
  • OFFLINE
  • Posts: 921
  • Thanks: 79
  • Karma: 8
7 years 9 months ago - 7 years 9 months ago #290112 by fribse2011
Replied by fribse2011 on topic Creating a user from a form
Ok, so I recreated the code to this:
Code:
<?php function registerUser( $fullName, $email, $username, $password, $approve = 0, $confirm = 0, $usergroups = array() ) { global $_CB_framework, $_PLUGINS, $ueConfig, $mainframe ; if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! 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' ); cbimport( 'cb.html' ); $approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve ); $confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm ); $user = new \CB\Database\Table\UserTable(); $user->set( 'username', $username ); $user->set( 'email', $email ); $user->set( 'name', $fullName ); $user->set( 'gids', array( (int) $_CB_framework->getCfg( 'new_usertype' ) ) ); $user->set( 'sendEmail', 0 ); $user->set( 'registerDate', $_CB_framework->getUTCDate() ); $user->set( 'password', $user->hashAndSaltPassword( $password ) ); $user->set( 'registeripaddr', cbGetIPlist() ); if ( $approval == 0 ) { $user->set( 'approved', 1 ); } else { $user->set( 'approved', 0 ); } if ( $confirmation == 0 ) { $user->set( 'confirmed', 1 ); } else { $user->set( 'confirmed', 0 ); } if ( ( $user->get( 'confirmed' ) == 1 ) && ( $user->get( 'approved' ) == 1 ) ) { $user->set( 'block', 0 ); } else { $user->set( 'block', 1 ); } $_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$user, &$user ) ); if ( $user->store() ) { if ( $user->get( 'confirmed' ) == 0 ) { $user->store(); } $messagesToUser = activateUser( $user, 1, 'UserRegistration' ); $_PLUGINS->trigger( 'onAfterUserRegistration', array( &$user, &$user, true ) ); if ( $user->get( 'block' ) == 1 ) { return false; } else { return true; } } return false; } /* Fields from form $form->data['mobil'] $form->data['adresse'] $form->data['post'] date_format( date_create_from_format( 'd-m-Y', $form->data['foedsel'] ), 'Y-m-d' ) $form->data['email'] $form->data['loginname'] $form->data['name'] $form->data['password'] */ echo 'Navn: '.$form->data['name'].' Email: '.$form->data['email'].' login: '.$form->data['loginname'].' Password: '.$form->data['password'].'<br >'; registerUser( $form->data['name'], $form->data['email'], $form->data['loginname'], $form->data['password'], 0 , 0, 9 ); ?>

The only modification is the 'name' variable, as I don't ask for firstname / lastname, but only full name.
the echo statement is there for debugging, and the fields are shown correctly with their content.
I don't see the user appear?

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: 7 years 9 months ago by fribse2011.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
7 years 9 months ago #290130 by krileon
Replied by krileon on topic Creating a user from a form
I don't know what to tell you. CB Connect and CB Auto Actions are both using that usage to register users and they work fine. You need xdebug output or php error logs to see where it's failing. Please be sure you're testing with debug mode and maximum error reporting enabled. Do an exit(); right after the function is ran if necessary to stop any further actions.

It's probably going to just be easier to fire a trigger with like 10 lines of code and let CB Auto Actions handle it so you don't have to maintain all of that code. You'd send $form->data array with your trigger and you'd be able to substitute in all of its values. Example as follows.

Code:
global $_PLUGINS; if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! 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' ); cbimport( 'cb.html' ); $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'custom_registerFormUser', array( $form->data ) );

With the above you'd act on the custom_registerFormUser trigger and substitute in user data with [var1_name], [var1_email], etc..


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
7 years 9 months ago - 7 years 9 months ago #290141 by fribse2011
Replied by fribse2011 on topic Creating a user from a form
Hi Kyle

Ok, you are absolutely right, that is probably going to be easier, especially with my limited PHP knowledge..

When I enter the values from the form in the CB register autoaction, how do I give the field values, I've tried the form field names in [] in {} and $form->data?

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: 7 years 9 months ago by fribse2011.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
7 years 9 months ago - 7 years 9 months ago #290144 by krileon
Replied by krileon on topic Creating a user from a form

When I enter the values from the form in the CB register autoaction, how do I give the field values, I've tried the form field names in [] in {} and $form->data?

With the exact usage shown above you'd just substitute in the values from var1, which is your $form->data array. Example as follows based off your code.

From:
Code:
$form->data['mobil']
To: [var1_mobil]


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: 7 years 9 months ago by krileon.
The following user(s) said Thank You: fribse2011

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

Moderators: beatnantkrileon
Powered by Kunena Forum