Support preselected selections
authorJoey Schulze <joey@infodrom.org>
Fri, 5 Mar 2010 17:15:28 +0000 (18:15 +0100)
committerJoey Schulze <joey@infodrom.org>
Fri, 5 Mar 2010 17:15:28 +0000 (18:15 +0100)
lib/mask.php

index 3ad3dd0..cbd6758 100644 (file)
@@ -59,7 +59,10 @@ function build_form($name, $mask)
       if (is_array($info['options'])) $options = $info['options'];
       else $options = query_db($info['options']);
       foreach ($options as $row)
       if (is_array($info['options'])) $options = $info['options'];
       else $options = query_db($info['options']);
       foreach ($options as $row)
-       $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
+       $ret[] = sprintf('<option value="%s"%s>%s</option>',
+                        $row['id'],
+                        !empty($info['selected']) && $row['id'] == $info['selected'] ? ' selected' : '',
+                        $row['text']);
       $ret[] = '</select>';
     } elseif ($info['type'] == 'textarea') {
       $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
       $ret[] = '</select>';
     } elseif ($info['type'] == 'textarea') {
       $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);