Totally Zenned
- Join Date:
- Aug 2007
- Location:
- Gijón, Asturias, Spain
- Posts:
- 2,880
- Plugin Contributions:
- 7
tiles, ids for form elements
Various items:
-
Drop down menu select options
The select should have an id so a <label> tag can be linked to it .e.g. <label for="id"
The select and options should have a title for accessibility as this gets used by screen readers.
SO
/*
* Output a form pull down menu
* Pulls values from a passed array, with the indicated option pre-selected
*/
function zen_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
$field = '<select name="' . zen_output_string($name) . '"';
if (zen_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>' . "\n";
if (empty($default) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) ) $default = stripslashes($GLOBALS[$name]);
for ($i=0, $n=sizeof($values); $i<$n; $i++) {
$field .= ' <option value="' . zen_output_string($values[$i]['id']) . '"';
if ($default == $values[$i]['id']) {
$field .= ' selected="selected"';
}
$field .= '>' . zen_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>' . "\n";
}
$field .= '</select>' . "\n";
if ($required == true) $field .= TEXT_FIELD_REQUIRED;
return $field;
}
To
/* steve modified to add title attributes
* Output a form pull down menu
* Pulls values from a passed array, with the indicated option pre-selected
*/
function zen_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
$field = '<select name="' . zen_output_string($name) . '"';
$field .= ' title="'.zen_output_string($name).'"';//steve added
$field .= ' id="'.zen_output_string($name).'"';//steve added
if (zen_not_null($parameters)) $field .= ' ' . $parameters;
$field .= '>' . "\n";
if (empty($default) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) ) $default = stripslashes($GLOBALS[$name]);
for ($i=0, $n=sizeof($values); $i<$n; $i++) {
$field .= ' <option value="' . zen_output_string($values[$i]['id']) . '"';
$field .= ' title="' . zen_output_string($values[$i]['text']) . '"';//steve added
if ($default == $values[$i]['id']) {
$field .= ' selected="selected"';
}
$field .= '>' . zen_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>' . "\n";
}
$field .= '</select>' . "\n";
if ($required == true) $field .= TEXT_FIELD_REQUIRED;
return $field;
}
-
Similarly for the input field, add an id and title
From
/*
* Output a form input field
*/
function zen_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {
$field = '<input type="' . zen_output_string($type) . '" name="' . zen_sanitize_string(zen_output_string($name)) . '"';
if ( (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) && ($reinsert_value == true) ) {
$field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"';
} elseif (zen_not_null($value)) {
$field .= ' value="' . zen_output_string($value) . '"';
}
if (zen_not_null($parameters)) $field .= ' ' . $parameters;
$field .= ' />';
return $field;
}
To
/*
* Output a form input field
*/
function zen_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {
$field = '<input type="' . zen_output_string($type) . '" name="' . zen_sanitize_string(zen_output_string($name)) . '"';
if ( (isset($GLOBALS[$name]) && is_string($GLOBALS[$name])) && ($reinsert_value == true) ) {
$field .= ' value="' . zen_output_string(stripslashes($GLOBALS[$name])) . '"';
} elseif (zen_not_null($value)) {
$field .= ' value="' . zen_output_string($value) . '"';
$field .= ' id="' . zen_output_string($name) . '"';//steve added for label "for"
}
$field .= ' title="' . zen_output_string($value) . '"';//steve added for accessibility
if (zen_not_null($parameters)) $field .= ' ' . $parameters;
$field .= ' />';
return $field;
}
-
And while we are changing this file, you could also get rid of the spaces around the title attributes that occur in three places, as attributes should not have whitespace around them.
Ie
From
```php
$image .= ' title=" ' . zen_output_string($alt) . ' "';
To
```php
$image .= ' title="' . zen_output_string($alt) . '"';//steve removed spaces
-
And sort of related... the sideboxes that have a drop-down, have the box name tagged as a label (the rest do not have any html tags).
Eg ```php
$title = '<label>' . BOX_HEADING_MANUFACTURERS . '</label>';
This gives it slightly different css formatting (which is not really relevant).
I understand that a label should also have a "for" attribute to link it to a form element or a form (html5). Reading around leads me to conclude that in html5 the label can be anywhere on the page if it is linked to a form rather than a form element. So it seems these labels need a "for" and the forms need an id, or get rid of the labels.
Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...