The User Ajax Example

nobicycle

New Member
Greetings
I am trying out the User Ajax example http://fabrikar.com/forums/index.php?wiki/user-ajax/
I copied the php example to components/com_fabrik/user_ajax.php
user_ajax.php already contains the userExists function, so I was expecting that if I edit the Java script for a field in a form, and paste the following (from the example), setting an onchange trigger, then it should raise a message if i type in "admin"

var thisElement = Fabrik.getBlock('form_2').elements.get('lll_client___name');
var myUsername = thisElement.get('value');
userExists(myUsername,thisElement);​

But nothing happens. Ajax validation is ON for the form, which has id=2. The table is lll_client and field name=name
 
You'd need to copy the JavaScript userExists() function from the wiki into a custom JS file, ./components/com_fabrik/js/form_X.js, where X is your form's numeric ID.

-- hugh
 
Hey
I do not know if I understood it well
file form_1.js I put the code:

JavaScript:
function userExists(myUsername,refocus) {
var url = "index.phpoption=com_fabrik&format=raw&task=plugin.userAjax&method=userExists&username=" + myUsername;
new Request({url:url,
onComplete: function(response) {
if (response != '') {
alert(response);
refocus.value = '';
refocus.focus();
}
}
}).send();
}

and I put in a file user_ajax.php:

PHP:
class UserAjax
{
    /**
     * This is the method that is run. You should echo out the result you which to return to the browser
     *
     * @return  void
     */

    public function userExists()
    {
        $db = FabrikWorker::getDbo();
        $query = $db->getQuery(true);
        $retStr = '';
        $app = JFactory::getApplication();
        $input = $app->input;
        $myUsername = $input->get('username', '');
        $query->select('name')->from('x_users')->where('username = ' . $db->quote($myUsername));
        $db->setQuery($query, 1, 0);
        $result = $db->loadResult();

        if ($thisName = $result)
        {
            $retStr = "The username $myUsername is already in use by $thisName";
        }

        echo $retStr;
    }
}

and in the event onchange for the field adds:

JavaScript:
var thisElement = Fabrik.getBlock('form_1').elements.get('test___name');
var myUsername = thisElement.get('value');
userExists(myUsername,thisElement);

Unfortunately this does not work for me, I get a strange message on multiple lines :(
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top