We have a diving club, but we also allow other people than members access to our website, except not to all of it.
So if people wants to be members they are taken through a few steps of entering their info (Chronoforms based), which is quite extended compared to the normal user creation.
Currently people then manually have to enter their info into the CB profile afterwards, and it would be nice to be able to help with the last few steps, and enter it automatically for them.
How would I go about taking the values from a form, and add them to an existing CB Profile?
So if people wants to be members they are taken through a few steps of entering their info (Chronoforms based), which is quite extended compared to the normal user creation.
Currently people then manually have to enter their info into the CB profile afterwards, and it would be nice to be able to help with the last few steps, and enter it automatically for them.
How would I go about taking the values from a form, and add them to an existing CB Profile?
Hi Fribse,
It's a long time since I looked at CB. This ought to be possible but I'm not sure how. I'd probably link in the ChronoForms CB registration action in to try to create a combined registration form.
Second choice would be to replicate the CB registration form using ChronoForms.
Third choice would be to look at a way to have a form copy over the data from your table to the CB tables behind the scenes. I think that the CB tables are quite complex so this might take some coding to setup.
Fourth choice would be to hack the CB form to pre-load the data.
Bob
It's a long time since I looked at CB. This ought to be possible but I'm not sure how. I'd probably link in the ChronoForms CB registration action in to try to create a combined registration form.
Second choice would be to replicate the CB registration form using ChronoForms.
Third choice would be to look at a way to have a form copy over the data from your table to the CB tables behind the scenes. I think that the CB tables are quite complex so this might take some coding to setup.
Fourth choice would be to hack the CB form to pre-load the data.
Bob
I thought about using the CB registration thing, but our users are sometimes only users of the website, before they decide to be clubmembers.
I think I'm going to look into putting the data straight into the table.
It's data for the currently logged in user, so it should be possible, but it's also very complicated, and probably more than I can do on my own, anyways, I'll give it a whack over the next period.
I think I'm going to look into putting the data straight into the table.
It's data for the currently logged in user, so it should be possible, but it's also very complicated, and probably more than I can do on my own, anyways, I'll give it a whack over the next period.
Oh well, I got this guide from JoomlaPolis, but it's getting way over my head:
http://www.allmysocials.com/directory/tutorials/item/232-establishing-user-object
It's a nice thought, but way to much for me :-)
http://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.
It's a nice thought, but way to much for me :-)
Hi Fribse,
Actually that's quite easy to do if you know which 'cb_field's you want to use.
Bob
Actually that's quite easy to do if you know which 'cb_field's you want to use.
<?php
$user =& JFactory::GetUser();
$user->cb_field = $form->data['some_input'];
$user->cb_field_2 = $form->data['some_other_input'];
. . .
$user->store();
?>
should be enough in a Custom Code action.Bob
Ok, that does look simple, thankyou very much, I'll try it out.
Btw. now that I'm testing on a seperate site I have full error messaging on, and I get these with my first form:
Notice: Undefined property: Tablechronoforms_emailverify::$id in /libraries/joomla/database/table.php on line 609
Notice: Undefined property: Tablechronoforms_emailverify::$id in /administrator/components/com_chronoforms/form_actions/db_save/db_save.php on line 122
Notice: Undefined property: Tablechronoforms_emailverify::$id in /administrator/components/com_chronoforms/form_actions/db_save/db_save.php on line 123
When I confirm it, I get routed back to my confirm form, and I see 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
Btw. now that I'm testing on a seperate site I have full error messaging on, and I get these with my first form:
Notice: Undefined property: Tablechronoforms_emailverify::$id in /libraries/joomla/database/table.php on line 609
Notice: Undefined property: Tablechronoforms_emailverify::$id in /administrator/components/com_chronoforms/form_actions/db_save/db_save.php on line 122
Notice: Undefined property: Tablechronoforms_emailverify::$id in /administrator/components/com_chronoforms/form_actions/db_save/db_save.php on line 123
When I confirm it, I get routed back to my confirm form, and I see 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
I tried modifying your suggestion to include the _CB_framework:
But that didn't change anything...
<?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 that didn't change anything...
Hi Fribse,
Assuming that the $form->data variables had values that code looks like valid PHP - so I'm afraid the question is one for the CB folks. Is the syntax correct from their end. Specifically is Global $_CB_framework; enough to load the framework - I'd suspect not.
Bob
Assuming that the $form->data variables had values that code looks like valid PHP - so I'm afraid the question is one for the CB folks. Is the syntax correct from their end. Specifically is Global $_CB_framework; enough to load the framework - I'd suspect not.
Bob
You were absolutely right, I needed some more code, which they kindly pointed me to, so this is the resulting code:
Now I need some sort of idiot proofing, so the user that's being updated is the one with the emailaddress given, and not the currently signed in user, as I can imagine a person getting his/her friend to sign up, while being logged in themselves.
<?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();
?>
Now I need some sort of idiot proofing, so the user that's being updated is the one with the emailaddress given, and not the currently signed in user, as I can imagine a person getting his/her friend to sign up, while being logged in themselves.
Hi Fribse,
You can get the current user Email, if they are logged in, from the Joomla User object (possibly also from the CB one):
Bob
You can get the current user Email, if they are logged in, from the Joomla User object (possibly also from the CB one):
<?php
$juser =& JFactory::getUser();
echo $juser->email; // or some other PHP
?>
Bob
Hi Bob
Thankyou for your help, so if the email found that way is the same as the one given in the form, then it should update.
Thankyou for your help, so if the email found that way is the same as the one given in the form, then it should update.
I guess it could be like this?
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();
};
Hmm, can't make it work.
I added a 'custom server side validation' object to the eventlist.
In that I wrote:
Then I added a 'thanks message' and a custom code that performed the storing if it's the right user, but this is not correct, and I can't figure out what to enter?
I added a 'custom server side validation' object to the eventlist.
In that I wrote:
<?php
$user =& JFactory::GetUser();
$user->email == $form->data['email1']
?>
Then I added a 'thanks message' and a custom code that performed the storing if it's the right user, but this is not correct, and I can't figure out what to enter?
Ah, got it sorted after searching high and low to snoop code from the forums 😀
That seems to do the trick.
Now there is just one issue left, it seems that the date field in C4 is not in the same format as the date field in CB (for birthdays).
The CB has a field type of 'date', CF4 uses text, but the date is entered with a datepicker function, so how do I convert it?
Best regards
Fribse
<?php
$user =& JFactory::GetUser();
if ($user->email <> $form->data['email1']) {
return false;
};
?>
That seems to do the trick.
Now there is just one issue left, it seems that the date field in C4 is not in the same format as the date field in CB (for birthdays).
The CB has a field type of 'date', CF4 uses text, but the date is entered with a datepicker function, so how do I convert it?
Best regards
Fribse
I tried doing it like this:
But that gave me a date of jan 1 1970, which I guess is zero in value?
$birthday = strtotime($form->data['foedsel1']);
$cbbirthday = date("Y-m-d", $birthday);
$user->cb_birthday = $cbbirthday;
But that gave me a date of jan 1 1970, which I guess is zero in value?
I've attached a couple of dumps of the two tables, it's the same user in the two tables.
Hi Fribse,
The foedsel1 date is set to ' 1 Januar 1980'. Two things about this - it stats with a space which may throw off the PHP parser. Secondly I have no idea if PHP will parse that date format correctly. I'd run a little test to see just what happens. You may need to set a Locale for it to identify the month from the text string.
A better solution would be to save the value of foedsel1 in a clean date format in the first place, like 'Y-m-d'.
Bob
The foedsel1 date is set to ' 1 Januar 1980'. Two things about this - it stats with a space which may throw off the PHP parser. Secondly I have no idea if PHP will parse that date format correctly. I'd run a little test to see just what happens. You may need to set a Locale for it to identify the month from the text string.
<?php
$test_date = ' 1 Januar 1980';
$test_date = trim($test_date);
echo strtotime($test_date);
echo date('Y-m-d', strtotime($test_date));
?>
A better solution would be to save the value of foedsel1 in a clean date format in the first place, like 'Y-m-d'.
Bob
Hi Fribse,
A better solution would be to save the value of foedsel1 in a clean date format in the first place, like 'Y-m-d'.
Better solutions is always a good selling point :-)
So I should change the datepicker config from
startView: 'years', format: '%e %B %Y'
to
startView: 'years', format: '%Y-%m-%d'
I'll try it out...
Ok, so that made it store it correctly, and it also makes CB understand it.
But it doesn't look pretty, can I change the way it is displayed in the form after it is selected with mootools datepicker?
But it doesn't look pretty, can I change the way it is displayed in the form after it is selected with mootools datepicker?
I tried using:
startView: 'years', format: '%d/%m-%Y', inputOutputFormat: '%Y-%m-%d'
but that didn't work, that just made it show with '13/4-1980' instead of '1980-04-13' which is good, but sadly, it also saved it as that, and not as it should.
startView: 'years', format: '%d/%m-%Y', inputOutputFormat: '%Y-%m-%d'
but that didn't work, that just made it show with '13/4-1980' instead of '1980-04-13' which is good, but sadly, it also saved it as that, and not as it should.
Just had a though... (impressive I know :-D)
If I enter it in the danish format:
d/m-Y
and then convert it to
Y-m-d
Both formats are well defined, so it should be ok.
I tried with this code, which I found on the net, and modified it a bit, as there were errors in it:
But my php 5.3.6 does not know the DateTime::createFromFormat function:
Fatal error: Call to undefined method DateTime::date_format() in /administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 24
That's at least as I understand it.
If I enter it in the danish format:
d/m-Y
and then convert it to
Y-m-d
Both formats are well defined, so it should be ok.
I tried with this code, which I found on the net, and modified it a bit, as there were errors in it:
$old = DateTime::createFromFormat('d/m-Y', $form->data['foedsel1']);
$new = $old->date_format('Y-m-d');
But my php 5.3.6 does not know the DateTime::createFromFormat function:
Fatal error: Call to undefined method DateTime::date_format() in /administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(18) : eval()'d code on line 24
That's at least as I understand it.
Ok, so I have to use procedural calls, and then it works, this code made it do the trick:
So now I could compress it to
which saved some silly variables :-)
And that made it work, it goes into CB, and it shows nicely on the mailtemplate and on the form.
$old = date_create_from_format('d/m-Y', $form->data['foedsel1']);
$new = date_format($old, 'Y-m-d');
So now I could compress it to
$user->cb_birthday = date_format(date_create_from_format('d/m-Y', $form->data['foedsel1']), 'Y-m-d');
which saved some silly variables :-)
And that made it work, it goes into CB, and it shows nicely on the mailtemplate and on the form.
This topic is locked and no more replies can be posted.