public static function input($name = null, $value = '', $right = 'class="fullWidth"') { if (is_array($name) && isset($name[0])) { $html = self::label($name[0], $name[1]); return $html . parent::input($name[0], $value, $right) . '<hr/>'; } return parent::input($name, $value, $right); }
public static function attributes($attr, $type = NULL) { // Hack to prevent the automatic creation of id attributes: // parent::attributes won't add an id if it finds a '[' character // in the name, so we prepend one, and then strip it out afterwards if (isset($attr['name'])) { $attr['name'] = '[' . $attr['name']; $str = parent::attributes($attr, $type); $str = str_replace('name="[', 'name="', $str); return $str; } else { return parent::attributes($attr, $type); } }
/** * Creates an HTML form label tag. * The data field can contain a string indicating what field this label belongs to, or it can be an array * with the following keys possible: * for - The name of what field this label is for. Should match the fieldname of the following input box/checkbox/etc. * issue - An error message/issue with the field to display (overrides hint), or if a boolean FALSE will suppress an error * hint - A small text string to show, in addition to the label * help - A help string to show. Based on the skin used, this is usually shown as a pop-up * In the above three data parameters, you can also pass the key in with a value that is an array containing additional attributes * * @param string|array label "for" name or an array of HTML attributes * @param string label text or HTML * @param string a string to be attached to the end of the attributes * @return string */ public static function label($data = '', $text = NULL, $extra = '') { // Add the Bluebox defaults (such as css classes) list($data, $text, $extra) = self::_addDefaults(__FUNCTION__, $data, $text, $extra); if (!empty($data['class'])) { $baseClasses = $data['class']; } else { $baseClasses = ''; } if (!empty($data['help'])) { // If only provided with a hint string make it into an array if (!is_array($data['help'])) { $data['help'] = array('value' => $data['help']); } // Load ID and class attributes if they are not already populated $data['help'] += array('id' => 'help_' . $data['id'], 'class' => $baseClasses . ' help'); // Pass the hint text to i18n() $value = self::_i18n($data['help']['value']); unset($data['help']['value']); unset($data['help']['url']); // Create the help element $text .= '<span' . html::attributes($data['help']) . ' tooltip="' . $value . '"> </span>'; $data = arr::update($data, 'class', ' has_help'); } if (!isset($data['issue']) || isset($data['issue']) && $data['issue'] !== false) { if (empty($data['issue']['value'])) { $data['issue']['value'] = self::_getError($data['for']); } if (!empty($data['issue']['value'])) { // Load ID and class attributes if they are not already populated $data['issue'] += array('id' => 'issue_' . $data['id'], 'class' => $baseClasses . ' issue'); $value = self::_i18n($data['issue']['value']); unset($data['issue']['value']); // Create the error element $text .= '<span' . html::attributes($data['issue']) . ' >' . $value . '</span>'; $has_error = TRUE; } } if (empty($has_error) && !empty($data['hint'])) { // If only provided with a hint string make it into an array if (!is_array($data['hint'])) { $data['hint'] = array('value' => $data['hint']); } // Load ID and class attributes if they are not already populated $data['hint'] += array('id' => 'hint_' . $data['id'], 'class' => $baseClasses . ' hint'); // Pass the hint text to i18n() $value = self::_i18n($data['hint']['value']); unset($data['hint']['value']); // Create the hint element $text .= '<span' . html::attributes($data['hint']) . ' >' . $value . '</span>'; $data = arr::update($data, 'class', ' has_hint'); } // Remove this element from the lable attributes if (isset($data['issue'])) { unset($data['issue']); } // Remove this element from the lable attributes if (isset($data['hint'])) { unset($data['hint']); } // Remove this element from the lable attributes if (isset($data['help'])) { unset($data['help']); } $data['for'] = trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['for']), '_'); // Call the parent $result = parent::label($data, $text, $extra); return $result; }