Add functions to print textarea and checkbox fields.
authorSam White <webmaster@ycra.org.uk>
Sat, 20 Nov 2021 16:43:33 +0000 (16:43 +0000)
committerSam White <webmaster@ycra.org.uk>
Sat, 20 Nov 2021 16:43:33 +0000 (16:43 +0000)
public_html/includes/fields.php

index 685825e7448126e75526df5c209bac5c6ce79683..ab04fc8667b56bf149e30f07e56c050559e76b4b 100644 (file)
@@ -50,6 +50,38 @@ function password_field($values, $name, $label, $attrs=[]) {
   general_field('password', $values, $name, $label, $attrs);
 }
 
+function textarea($values, $name, $label, $attrs=[]) {
+  if (!array_key_exists('rows', $attrs)) $attrs['rows'] = '6';
+  if (!array_key_exists('cols', $attrs)) $attrs['cols'] = '50';
+
+  $value = get_sent_field_value($values, $name);
+  $id = get_field_id($name);?>
+
+  <div class="field textual-input<?php esc(array_key_exists('required', $attrs) ? ' required'
+                                                                  : '');?>"><?php
+    field_label($name, $label);?>
+
+    <textarea name="<?php esc($name);?>" id="<?php esc($id);?>" <?php
+              print_attrs($attrs);?>><?php
+      esc($value);
+    ?></textarea>
+  </div><?php
+}
+
+function checkbox_field($values, $name, $label, $attrs=[]) {
+  $checked = get_sent_field_value($values, $name);
+  if ($checked) $attrs['checked'] = '';
+
+  $id = get_field_id($name);?>
+
+  <div class="field">
+    <input type="checkbox" name="<?php esc($name);?>" id="<?php esc($name);?>"
+          value="1" <?php print_attrs($attrs);?> /><?php
+
+    field_label($name, $label);?>
+  </div><?php
+}
+
 function hidden_field($name, $value) {
   general_bare_field('hidden', [$name=>$value], $name);
 }