Here is some code from that project.
First my code for the position override of the search form.
<?php
$jyaml = JYAML::getDocument();
$jyaml->addScript($jyaml->getUrl('script', 'jquery.autocomplete.min.js'));
//require_once 'templates/seb_one/positions/lehrerliste/search/search.php';
?>
<p><?php echo JText::_('COM_CCK_SORTIERT_NACH_PLZ'); ?></p>
<?php echo $cck->renderField('gbr_lehrer_suchtext'); ?>
<div id="gbrsearch">
<?php echo $cck->renderField('cck'); ?>
<?php echo $cck->renderField('gbr_user_list'); ?>
<span class="no1"><?php echo $cck->renderField('user_name'); ?>
<?php echo $cck->renderField('gbr_user_plz'); ?></span><br />
<span class="no2"><?php echo $cck->renderField('gbr_user_cert_dd'); ?></span>
<div style="clear:both;"></div>
<?php echo $cck->renderField('button_submit'); ?>
</div>
<script type="text/javascript">
function selectItem(li) {
return false;
}
function formatItem(row) {
return row[0] + "<br><i>" + row[1] + "</i>";
}
var baseuri = '<? echo JURI::base(); ?>';
$j().ready(function() {
$j("#gbr_user_plz").autocomplete(baseuri + '/components/com_gbrajaxcall/platform/autocompplz.php', {
width: 200,
selectFirst: false
});
$j("#user_name").autocomplete(baseuri + 'components/com_gbrajaxcall/platform/autocompname.php', {
width: 200,
selectFirst: false
});
});
</script>
I am using
jQuery autocomplete script.
You can see a call to /components/com_gbrajaxcall/platform/autocompplz.php.
This file must be placed within the Joomla component folder, otherwise Joomla doesn't allow Ajax Calls. I created a folder /components/com_gbrajaxcall. In that folder is a folder "platform".
There I placed a file /components/com_gbrajaxcall/platform/joomla_platform.php:
<?php
/* If not already done, initialize Joomla framework */
if (!defined('_JEXEC')) {
//init Joomla Framework
define( '_JEXEC', 1 );
}
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..' )); // print this out or observe errors to see which directory you should be in
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
// require_once( JPATH_CONFIGURATION .DS.'configuration.php' );
// require_once ( JPATH_LIBRARIES .DS.'joomla'.DS.'database'.DS.'database.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
require_once ( JPATH_LIBRARIES .DS.'import.php' );
JFactory::getApplication('site')->initialise();
?>
And a file autocompplz.php for fetching the data from the database:
<?php
define('_JEXEC', 1);
// Fix magic quotes.
@ini_set('magic_quotes_runtime', 0);
// Maximise error reporting.
@ini_set('zend.ze1_compatibility_mode', '0');
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'joomla_platform.php';
$q = strtolower($_GET["q"]);
if (!$q) return;
$db = JFactory::getDBO();
$query = "SELECT gbr_user_plz,gbr_user_ort FROM j25_cck_store_form_user WHERE gbr_user_plz LIKE '".$q."%' ";
$db->setQuery( $query );
$row = $db->loadAssocList();
foreach($row as $id => $assoc) {
echo "$assoc[gbr_user_plz] $assoc[gbr_user_ort]|$assoc[gbr_user_plz]\n";
}
?>
This all together gives you a autocomplete field. You can
see it in action here. The fields Name and Postleitzahl in the "Lehrersuche" box.
Hope this helps
Gerhard