Add helper to validate multiple fields.
authorSam White <webmaster@ycra.org.uk>
Sun, 24 Oct 2021 15:30:49 +0000 (15:30 +0000)
committerSam White <webmaster@ycra.org.uk>
Sun, 24 Oct 2021 15:30:49 +0000 (15:30 +0000)
public_html/includes/form-validation.php

index 43ab85e041a360563c7068c988de58bd39e26f4f..dfbb8f54cd8eaeb70cf78f1f022fa22dafe9ba4d 100644 (file)
@@ -1,6 +1,15 @@
 <?php
 require_once('includes/utils.php');
 
+function require_fields(&$errors, $data, $keys, $names=null) {
+  if (!is_null($names)) {
+    foreach (array_keys($keys) as $i)
+      require_field($errors, $data, $keys[$i], $names[$i]);
+  }
+  else
+    foreach ($keys as $key) require_field($errors, $data, $key);
+}
+
 function require_field(&$errors, $data, $key, $name=null) {
   if (is_null($name)) $name = key_to_human_text($key);