Hallo ich bin nicht so fit in dem Theama. Kann mir bitte jemand helfen dropdown lists in typo3 zu implementieren. Es müssen "nur" die nachfolgenden zwei Codes zusammengeführt werden.
Ich habe eine Extension im Kickstarter erstellt und möchte die Klassendatei (class.tx_xxx__p1.php) modifizieren.
Wenn das geschafft ist, möchte ich die statischen Arrays durch DB Abfragen ersetzen.
Danke schon mal, falls sich ein Hilfsbereiter Typo3ler finder!!!
Gruß,
Dirk
<?php
require_once(PATH_tslib.'class.tslib_pibase.php');
class tx_productfinder_pi1 extends tslib_pibase {
var $prefixId = 'tx_productfinder_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_productfinder_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'productfinder'; // The extension key.
var $pi_checkCHash = TRUE;
/**
* [Put your description here]
*/
var $xajax;
function main($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
$this->pi_USER_INT_obj = 1;
$content = '';
require_once(t3lib_extMgm::extPath('xajax') . 'class.tx_xajax.php');
$this->xajax = t3lib_div::makeInstance('tx_xajax');
$this->xajax->setWrapperPrefix($this->prefixId);
$this->xajax->registerFunction(array('ladeUndZeigeZeit', &$this, 'ladeUndZeigeZeit'));
$this->xajax->processRequests();
$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('xajax'));
$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] .= '<script type="text/javascript">
window.onload = function() {
window.setInterval("' . $this->prefixId . 'ladeUndZeigeZeit();", 1000);
}</script>';
$content .= '<div>Serverzeit: <span id="Serverzeit"></span></div>';
return $this->pi_wrapInBaseClass($content);
}
function ladeUndZeigeZeit() {
$content = date("H:i:s");
$antwort = new tx_xajax_response();
$antwort->addAssign("Serverzeit", "innerHTML", $content);
return $antwort->getXML();
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/productfinder/pi1/class.tx_productfinder_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/productfinder/pi1/class.tx_productfinder_pi1.php']);
}
?>
Nachfolgender Quellcode ist von hier: http://www.fornewbie.com/article/php/create_ajax_dynamic_drop_down_list_using_php_-_xajax.html
<?php
require_once('xajax.inc.php');
class myXajaxResponse extends xajaxResponse {
function addCreateOptions($sSelectId, $options) {
$this->addScript("document.getElementById('".$sSelectId."').length=1");
if (sizeof($options) >0) {
foreach ($options as $option) {
$this->addScript("addOption('".$sSelectId."','".$option."','".$option."');");
}
}
}
}
?>
<?
$mode = array('air','water','land');
$transports = array(
'air'=>array('plane','helicopter','air-baloon'),
'water'=>array('boat','watersky','submarine'),
'land'=>array('motorcycle','car')
);
$brands = array(
'plane'=>array('Boeing707', 'F-16', 'Columbia'),
'helicopter'=>array('BayWatch Heli', 'Police Heli'),
'air-baloon'=>array('Zeppelin'),
'boat'=>array('Baywatch Safeguard Boat', 'JetBoat'),
'watersky'=>array('JetSky','Board-Sky'),
'submarine'=>array('K-19'),
'motorcycle'=>array("Yamaha", "Harley Davidson", "Ducati"),
'car'=>array("Hummer", "Renault", "Porsche")
);
$xajax = new xajax();
//$xajax->debugOn();
// adds an option to the select
function addTransports($selectId, $mode) {
global $transports;
$objResponse = new myXajaxResponse();
$data = $transports[$mode];
$objResponse->addCreateOptions($selectId, $data);
return $objResponse->getXML();
}
function addBrands($selectId, $transport) {
global $brands;
$objResponse = new myXajaxResponse();
$data = $brands[$transport];
$objResponse->addCreateOptions($selectId, $data);
return $objResponse->getXML();
}
$xajax->registerFunction("addTransports");
$xajax->registerFunction("addBrands");
$xajax->processRequests();
?>
<?
if (isset($_POST['Submit'])) {
print_r($_POST);
}
?>
<html>
<head>
<title>AJAX Dynamic Drop Down Tutorial</title>
<?
$xajax->printJavascript();
?>
<script type="text/javascript">
function addOption(selectId, val, txt) {
var objOption = new Option(txt, val);
document.getElementById(selectId).options.add(objOption);
}
</script>
</head>
<body>
<form name="form1" method="POST" action="">
Type :
<select name="type" id="type" onchange="xajax_addTransports('transports', document.form1.type.value)">
<option value="">--select--</option>
<? foreach ($mode as $mod) { ?>
<option value="<?= $mod?>"><?= $mod?></option>
<? } ?>
</select>
Transportation :
<select name="transports" id="transports" onchange="xajax_addBrands('brands', document.form1.transports.value)"><option value="">--select--</option>
</select>
Brands :
<select name="brands" id="brands"><option value="">--select--</option>
</select>
<input type="submit" value="Submit" name="Submit" id="Submit" />
</form>
</body>
</html>