summaryrefslogtreecommitdiff
path: root/inc/form.php
diff options
context:
space:
mode:
authorMichael Klier <chi@chimeric.de>2007-10-29 15:10:13 +0100
committerMichael Klier <chi@chimeric.de>2007-10-29 15:10:13 +0100
commit12bbca2e0528f983d529885c32fb98e7d411be0e (patch)
treef34dddbc3431582bd8d2ae1811564e9eec524f29 /inc/form.php
parent3e182cc04a2ccc158b57996f1c1fc20957b6422b (diff)
downloadrpg-12bbca2e0528f983d529885c32fb98e7d411be0e.tar.gz
rpg-12bbca2e0528f983d529885c32fb98e7d411be0e.tar.bz2
added makeFileField method to form class
darcs-hash:20071029141013-23886-ca99a6bff50766f2015f071d89fcc3265746b3b5.gz
Diffstat (limited to 'inc/form.php')
-rw-r--r--inc/form.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/inc/form.php b/inc/form.php
index 77b76dd15..fbba80296 100644
--- a/inc/form.php
+++ b/inc/form.php
@@ -428,6 +428,21 @@ function form_makePasswordField($name, $label=null, $id='', $class='', $attrs=ar
}
/**
+ * form_makeFileField
+ *
+ * Create a form element for a file input element with label
+ *
+ * @see form_makeField
+ * @author Michael Klier <chi@chimeric.de>
+ */
+function form_makeFileField($name, $label=null, $id='', $class='', $attrs=array()) {
+ if (is_null($label)) $label = $name;
+ $elem = array('_elem'=>'filefield', '_text'=>$label, '_class'=>$class,
+ 'id'=>$id, 'name'=>$name, 'class'=>'edit');
+ return array_merge($elem, $attrs);
+}
+
+/**
* form_makeCheckboxField
*
* Create a form element for a checkbox input element with label.
@@ -729,6 +744,31 @@ function form_passwordfield($attrs) {
}
/**
+ * form_filefield
+ *
+ * Print the HTML for a file input field.
+ * _class : class attribute used on the label tag
+ * _text : Text to display before the input. Not escaped
+ * _maxlength : Allowed size in byte
+ * _accept : Accepted mime-type
+ * Other attributes are passed to buildAttributes() for the input tag
+ *
+ * @author Michael Klier <chi@chimeric.de>
+ */
+function form_filefield($attrs) {
+ $s = '<label class="'.$attrs['_class'].'"';
+ if (!empty($attrs['id'])) $s .= ' for="'.$attrs['id'].'"';
+ $s .= '><span>'.$attrs['_text'].'</span> ';
+ $s .= '<input type="file" '.buildAttributes($attrs,true);
+ if (!empty($attrs['_maxlength'])) $s .= ' maxlength="'.$attrs['_maxlength'].'"';
+ if (!empty($attrs['_accept'])) $s .= ' accept="'.$attrs['_accept'].'"';
+ $s .= '/></label>';
+ if (preg_match('/(^| )block($| )/', $attrs['_class']))
+ $s .= '<br />';
+ return $s;
+}
+
+/**
* form_checkboxfield
*
* Print the HTML for a checkbox input field.