See the details here
index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=userExists&username=" + myUsername;
$app = JFactory::getApplication();
$input = $app->input;
$input->getString('variablename');
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();
}
var thisElement = Fabrik.getBlock('form_1').Elements.get('jos_fabrik_formdata_13___username');
var myUsername = thisElement.get('value');
userExists(myUsername,thisElement);
function ajaxTest() {
var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=etStateDropDown";
new Request({url:url,
method: 'get',
update: document.id('jos_fabrik_formdata_13___states')
}).send();
}
/**
* Define your userAjax class
*
* @package Joomla
* @subpackage Fabrik
* @since 3.0
*/
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->getString('username', '');
$query->select('name')->from('#__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;
}
}
jQuery(document).on("click", ".myvalid > i", function() {
mythis = jQuery(this);
mytr = jQuery(this).parents("tr");
myrowid = mytr.find("td").eq(0).html();
myrowid = jQuery.trim(myrowid);
mystatus = jQuery(this).attr("class");
mystatus = jQuery.trim(mystatus);
jQuery.ajax({
url: 'index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=ToggleYesNo&row_id='+myrowid+'&row_status='+mystatus,
type: "GET",
success: function(data) {
if(mystatus === "icon-remove") {
mythis.removeClass('icon-remove');
mythis.addClass('icon-checkmark');
} else {
mythis.removeClass('icon-checkmark');
mythis.addClass('icon-remove');
}
}
});
});
public function ToggleYesNo()
{
$mydb = JFactory::getDBO();
$app = JFactory::getApplication();
$input = $app->input;
$row_id = $input->get('row_id', '');
$mystatus = $input->get('row_status', '');
if ($mystatus == "icon-checkmark") {
$query = "UPDATE mytable SET active = '0' WHERE id = ".$mydb->Quote($row_id);
} else {
$query = "UPDATE mytable SET active = '1' WHERE id = ".$mydb->Quote($row_id);
}
$mydb->setQuery($query);
$mydb->execute();
}