0

I run a fantasy football website. My League Registration is handled through a form and mysql database. This all works well. Once I hire a manager, I want to create a Joomla user for the user.

I have a 'Hire Manager' module that I've created. In that module, you select the waiting list person, then it checks if there is an existing email address in Joomla for that user. Again, all of this works fine.

Within that 'Hire Manager' module, I have an event that will gather the Waiting List information. There is an 'on change/blur' even that fires. This will check for the existence of a user through an Ajax call (and this works). On Success, I want it to create a Joomla user. I've found code that will create the user:

$JRoot = $_SERVER['DOCUMENT_ROOT'] . "/*joomla_root_folder*/"; 
define( '_JEXEC', 1 );
define('JPATH_BASE', $JRoot );
define('JPATH_ROOT', $JRoot );
define( 'DS', DIRECTORY_SEPARATOR );

$defines = $JRoot . "/includes/defines.php";
$framework = $JRoot . "/includes/framework.php";
require_once ($defines);
require_once ($framework);

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

    jimport( 'joomla.user.helper');
    $data = array(
        "name"=>$_POST['name'],
        "username"=>$_POST['username'],
        "password"=>$_POST['password'],
        "password2"=>$_POST['password'],
        "email"=>$_POST['email'],
        "block"=>0,
        "groups"=>array ("1" ,"2", "3" )
        );

    $user = new JUser;
    if(!$user->bind($data)) {
        throw new Exception("Could not bind data. Error: " . $user->getError());
}
if (!$user->save()) {
    throw new Exception("Could not save user. Error: " . $user->getError());
}

But this fails during the execution with Class 'JFile' not found... This error usually occurs in my code if there is an issue with the sql statement in a PDO call.

I tested to assure the $_POST variables here are valid.

1 Answer 1

1

I figured out the issue. The problem was that I was calling the event on change AND on blur. So it ran correctly on change (and created the record), but when it tried to run again on blur - it would fail because the record already existing for that email address and email address is a unique field. DOPE !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.