2

I have a external script for a web app connected to Joomla database This is for user registration Source : https://gist.github.com/AdamMadrzejewski/2581730241748da89798

<?php
require_once __DIR__ . '/db_connect.php';

$type = '0';
$username = 'username';
$password = 'pass';
$name = 'john';
$mobile = '9090909090';
$email = '[email protected]';
$alias = strtr($name, array (' ' => '-'));



 define( '_JEXEC', 1 );
 define('JPATH_BASE', dirname(__FILE__) );
 define( 'DS', DIRECTORY_SEPARATOR );

 require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
 require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

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



 require_once(JPATH_BASE.DS.'components'.DS.'com_users'.DS.'models'.DS.'registration.php');


 $lang = JFactory::getLanguage();
    $extension = 'com_users';
    $base_dir = JPATH_SITE;
    $language_tag = 'en-GB';
    $reload = true;
    $lang->load($extension, $base_dir, $language_tag, $reload);

 $model = new UsersModelRegistration();
 jimport('joomla.mail.helper');
 jimport('joomla.user.helper');




 $block = '0';
 $sendEmail = '0';
 $activation = '1';
 $data = array( 'username' => $username,
 'name' => $name,
 'email1' => $email,
 'password1' => $password, // First password field
 'password2' => $password, // Confirm password field
 'sendEmail' => $sendEmail,
 'activation' => $activation,
 'mobile' => $mobile,
 'groups' =>array("2","10"));
  $response = $model->register($data);
  echo $data['mobile'];

Expected result is store all the values including a custom field called 'mobile' in #__users table

but it stores all the values except for mobile I have added declared the variable

$mobile = null; // line 60 at root/libraries/joomla/user/user.php

Adding value at com_users/models/forms/registration.xml doesn't help

<field
        name="mobile"
        type="text"
        description="COM_USERS_DESIRED_USERNAME"
        filter="mobile"
        label="COM_USERS_REGISTER_USERNAME_LABEL"
        message="COM_USERS_REGISTER_USERNAME_MESSAGE"

        size="30"   />

But somehow it doesnt store only mobile value in the table

Where am i going wrong ? This code calls the function com_users/models/registration.php

public function register() 

Where exactly should I modify to add the value 'mobile'? Appreciate the help!

1

1 Answer 1

1

The following testcode works

<?php 
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__);
define('DS', DIRECTORY_SEPARATOR);

/* Required Files */
require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$app = JFactory::getApplication('site');
$app->initialise();

require_once(JPATH_BASE . DS . 'components' . DS . 'com_users' . DS . 'models' . DS . 'registration.php');
//not necessary
//require_once(JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'application'.DS.'component'.DS.'helper.php';

$model = new UsersModelRegistration();
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$language = JFactory::getLanguage();
$language->load('com_users', JPATH_SITE);
$type       = '0';
$username   = 'username';
$password   = 'pass';
$name       = 'john';
$mobile     = '9090909090';
$email      = '[email protected]';
$alias      = strtr($name, array(' ' => '-'));
$username   = 'adam';
$name       = 'adam24';
$email      = '[email protected]';
$password   = 'adam';
$block      = '0';
$sendEmail  = '0';
$activation = '1';
$data       = array('username'   => $username,
            'name'       => $name,
            'email1'     => $email,
            'password1'  => $password, // First password field
            'password2'  => $password, // Confirm password field
            'sendEmail'  => $sendEmail,
            'activation' => $activation,
            'mobile'     => $mobile,
            'groups'     => array("2", "10"));
$response   = $model->register($data);
echo $data['mobile'];

echo $model->register($data);
if (version_compare(PHP_VERSION, '5.3.1', '<')) {
    die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!');
}
?>

<!-- db result -->
<tr>
    <th>id</th>
    <th>name</th>
    <th>username</th>
    <th>email</th>
    <th>password</th>
    <th>block</th>
    <th>sendEmail</th>
    <th>registerDate</th>
    <th>lastvisitDate</th>
    <th>activation</th>
    <th>params</th>
    <th>lastResetTime</th>
    <th>resetCount</th>
    <th>otpKey</th>
    <th>otep</th>
    <th>requireReset</th>
    <th>mobile</th>
</tr>

<tr>
    <td>382</td>
    <td>adam24</td>
    <td>adam</td>
    <td>[email protected]</td>
    <td>$2y$10$CWsR0Ab9AZNvze2l/2Teiek3mzZ3EqyxnAzuYcv9CTaMCeSud5pza</td>
    <td>1</td>
    <td>0</td>
    <td>2015-10-26 22:16:16</td>
    <td>NULL</td>
    <td>fa37ff46e1be16c6029723c395c0f156</td>
    <td>{}</td>
    <td>NULL</td>
    <td>0</td>
    <td></td>
    <td></td>
    <td>0</td>
    <td>9090909090</td>
</tr>

$mobile = null; // line 60 at root/libraries/joomla/user/user.php

The mobile var must not to be declared in library. The Table->bind method is really flexible.

During the load via JFactory::getUser('adams_id'); it has also load the mobile.

3
  • Hey JProof, I tried it but still the same. it doesnt stores it. Commented Oct 27, 2015 at 3:57
  • Hello Srinath, perhaps you plugins installed, they are not Joomla-Core? Perhaps you have some buggy testcode inside? Did you use an PHP-IDE such as phpstorm to see errors or misspelling? **Try to setup an fresh joomla an insert only the testcode file into the joomla root. **
    – JProof
    Commented Oct 27, 2015 at 6:57
  • @JProof Please vote in our joomla.stackexchange.com/election Commented May 7, 2021 at 0:14

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.