Forums

[SOLVED] Fatal error: Call to a member function....with CB

david.kwock 16 Jan, 2013
Hi,

I have inserted one custom code on the form and I got this error:

Fatal error: Call to a member function myId() on a non-object in /home/computit/public_html/smartt/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(19) : eval()'d code on line 4



And this is my custom code and this is to retrieve user data from CB profile:
<?php
Global $_CB_framework;
 
$myId		=	$_CB_framework->myId();
$cbUser		=&	CBuser::getInstance( $myId );
 
if ( ! $cbUser ) {
	$cbUser	=&	CBuser::getInstance( null );
}
$user		=&	$cbUser->getUserData();
$name	=	$cbUser->getField('cb_company');
$mobile	=	$cbUser->getField('cb_mobile');
?>

This custom code is verified from one of member in CB team you can find that code from:
http://www.allmysocials.com/directory/tutorials/item/232-establishing-user-object

Strange thing is that If I use the form as a module, it is working OK but the form validation is not..
Please help me to resolve this issue. Thank you.
GreyHead 16 Jan, 2013
Hi David,

This is line 4 of your Custom Code
$myId      =   $_CB_framework->myId();
so it looks as though the CB Framework isn't loaded. You need to add whatever line is necessary to do that. Using the global command will only make it available if it is already loaded by some other component, so if the form is in a CB page you are probably OK, if not then you get the error.

Bob
david.kwock 17 Jan, 2013
Thank you Bob,

Now I can understand why this is happening. and I have solved this problem by enabling a hidden CB module on the same page. Thank you again for your prompt answer!😀
This topic is locked and no more replies can be posted.