Project

General

Profile

Bug #14921 » FORM-ids-accessibility.patch

Administrator Admin, 2005-08-11 18:06

View differences:

t3lib/jsfunc.validateform.js 11 Aug 2005 15:46:13 -0000
function validateForm(theFormname,theFieldlist,goodMess,badMess,emailMess) {
if (document[theFormname] && theFieldlist) {
var formname = document[theFormname];
if (!formname) {
formname = document.getElementById(theFormname);
}
if (formname && theFieldlist) {
var index=1;
var theField = split(theFieldlist, ",", index);
var msg="";
......
index++;
theLabel = unescape(split(theFieldlist, ",", index));
theField = unescape(theField);
if (document[theFormname][theField]) {
var fObj = document[theFormname][theField];
if (formname[theField]) {
var fObj = formname[theField];
var type=fObj.type;
if (!fObj.type) {
type="radio";
typo3/sysext/cms/tslib/class.tslib_content.php 11 Aug 2005 15:46:14 -0000
$fieldname_hashArray = Array();
$cc = 0;
$xhtmlStrict = t3lib_div::inList('xhtml_strict,xhtml_11,xhtml_2',$GLOBALS['TSFE']->config['config']['doctype']);
// Formname;
$formname = $GLOBALS['TSFE']->uniqueHash();
$formname = $this->cleanFormName($conf['formName']);
if (!$formname) {
$formname = $GLOBALS['TSFE']->uniqueHash();
}
if (ctype_digit($formname{0})) { // form name must start with a letter
$formname = 'a'.$formname;
}
$prefix = $formname.'_';
if(isset($conf['fieldPrefix'])) {
if ($conf['fieldPrefix'] == '0') {
$prefix = '';
} else {
$prefix = $this->cleanFormName($conf['fieldPrefix']);
}
}
foreach($dataArr as $val) {
$cc++;
......
$typeParts = explode('=',$fParts[0]);
$confData['type'] = trim(strtolower(end($typeParts)));
if (count($typeParts)==1) {
$confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
$confData['fieldname'] = $this->cleanFormName($parts[0]);
if (strtolower(ereg_replace('[^[:alnum:]]','',$confData['fieldname']))=='email') {$confData['fieldname']='email';}
// Duplicate fieldnames resolved
if (isset($fieldname_hashArray[md5($confData['fieldname'])])) {
......
if (strcmp('',$addParams)) $addParams=' '.$addParams;
} else $addParams='';
if ($conf['dontMd5FieldNames']) {
$fName = $confData['fieldname'];
} else {
$fName = md5($confData['fieldname']);
}
// Accessibility: Set id = fieldname attribute:
if ($conf['accessibility']) {
$elementIdAttribute = ' id="'.$formname.'_'.md5($confData['fieldname']).'"';
if ($conf['accessibility'] || $xhtmlStrict) {
$elementIdAttribute = ' id="'.$prefix.$fName.'"';
} else {
$elementIdAttribute = '';
}
......
break;
case 'radio':
$option='';
if ($conf['accessibility'] || $xhtmlStrict) {
$option.='<fieldset'.$elementIdAttribute.'>';
}
$valueParts = explode(',',$parts[2]);
$items=array(); // Where the items will be
$default='';
......
$default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], $default);
// Create the select-box:
for($a=0;$a<count($items);$a++) {
$option.= '<input type="radio" name="'.$confData['fieldname'].'"'.$elementIdAttribute.' value="'.$items[$a][1].'"'.(!strcmp($items[$a][1],$default)?' checked="checked"':'').''.$addParams.' />';
$option.= $this->stdWrap(trim($items[$a][0]), $conf['radioWrap.']);
$radioId = $prefix.$fName.$this->cleanFormName($items[$a][0]);
if ($conf['accessibility']) {
$radioLabelIdAttribute = ' id="'.$radioId.'"';
} else {
$radioLabelIdAttribute = '';
}
$option.= '<input type="radio" name="'.$confData['fieldname'].'"'.$radioLabelIdAttribute.' value="'.$items[$a][1].'"'.(!strcmp($items[$a][1],$default)?' checked="checked"':'').''.$addParams.' />';
if ($conf['accessibility']) {
$option.= '<label for="'.$radioId.'">' . $this->stdWrap(trim($items[$a][0]), $conf['radioWrap.']) . '</label>';
} else {
$option.= $this->stdWrap(trim($items[$a][0]), $conf['radioWrap.']);
}
$option.= '<br />';
}
if ($conf['accessibility'] || $xhtmlStrict) {
$option.='</fieldset>';
}
$fieldCode = $option;
break;
case 'hidden':
......
// Field:
$fieldLabel = $confData['label'];
if ($conf['accessibility']) {
$fieldLabel = '<label for="'.$formname.'_'.md5($confData['fieldname']).'">'.$fieldLabel.'</label>';
if ($conf['accessibility'] && $confData['type'] != 'label') {
$fieldLabel = '<label for="'.$prefix.$fName.'">'.$fieldLabel.'</label>';
}
// Getting template code:
......
$content = Array(
'<form'.
' action="'.htmlspecialchars($action).'"'.
' name="'.$formname.'"'.
($xhtmlStrict?' id="':' name="').$formname.'"'.
' enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'"'.
' method="'.($conf['method']?$conf['method']:'post').'"'.
($theTarget ? ' target="'.$theTarget.'"' : '').
......
return implode('',$content);
}
}
/**
* Rendering the cObject, SEARCHRESULT
*
......
return $altParam;
}
/**
* removes forbidden characters and spaces from name/id attributes in the form tag and formfields
*
* @param string Input string
* @return string the cleaned string
* @see FORM()
*/
function cleanFormName($name) {
// turn data[x][y] into data:x:y:
$name = ereg_replace('\[|\]\[?',':',trim($name));
// replace illegal chars with _
return substr(ereg_replace('[^:a-zA-Z0-9_]','',str_replace(' ','_',trim($name))),0,30);
}
(1-1/3)