$html = '';
- $values = (array)$values;
- $suff = count( $values ) > 1 ? '[]' : '';
+ $multi = is_array($values) ? true : false;
+ $suff = $multi ? '[]' : '';
if ($type === null) $type = $this->html_type();
- foreach ($values as $value) {
+ foreach ((array)$values as $value) {
$html .= '<div class="label '.$this->name.'">'
.'<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
;
}
$html .= '<'.$tag
- .' name="'.$this->preffix.$this->name.$suff.'"'
+ .' name="'.$this->preffix.$this->name . ($multi ? '[]' : '') . '"'
.( ($size and $tag != 'textarea') ? ' size="'.$size.'"' : '')
.($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />')
;
}
# If more than one value, add js code to add more values
- if ($suff) $html .= '<a href="#" onclick="var i=this.parentNode;var j=i.cloneNode(true);j.querySelectorAll(\'input, textarea, select\').forEach(function(e) {e.value=\'\';}); i.parentNode.insertBefore(j, i.nextSibling);console.log(i.className); return false;">+</a>';
+ if ($multi) $html .= '<a href="#" onclick="var i=this.parentNode;var j=i.cloneNode(true);j.querySelectorAll(\'input, textarea, select\').forEach(function(e) {e.value=\'\';}); i.parentNode.insertBefore(j, i.nextSibling);console.log(i.className); return false;">+</a>';
$html .= '</div>'.NB_EOL;
}