Grima 2018-08
Whispering into Alma's ear
Public Member Functions | Public Attributes | Protected Attributes | List of all members
GrimaFormField Class Reference

Wrapper for each field in a form, keeping track of its properties. More...

Public Member Functions

  booly ($str, $default='undefined')
  return boolean meaning of common terms ("true","on","1","yes") More...
 
  __construct ($field)
  create a new GrimaFormField More...
 

Public Attributes

  $value
 
  $name
 
  $shortname
 
  $label
 
  $placeholder
 
  $required
 
  $persistent
 
  $autofocus
 
  $visible
 
  $rows
 
  $dataset
 
  $error_condition = ""
 
  $error_message = ""
 

Protected Attributes

  $autocomplete
 
  $highlight
 

Detailed Description

Wrapper for each field in a form, keeping track of its properties.

Definition at line 2073 of file grima-lib.php.

Constructor & Destructor Documentation

◆ __construct()

GrimaFormField::__construct (   $field )

create a new GrimaFormField

Parameters
DomNode $field with attributes for all properties

Definition at line 2128 of file grima-lib.php.

2129 {
2130 $this->name = $field->getAttribute('name');
2131 $this->shortname = $field->getAttribute('shortname');
2132 $this->label = $field->getAttribute('label');
2133 $this->placeholder = $field->getAttribute('placeholder');
2134 $this->rows = $field->getAttribute('rows');
2135 $this->type = $field->getAttribute('type');
2136 if (!$this->type) {
2137 $this->type = 'input';
2138 }
2139 $this->required = $this->booly($field->getAttribute('required'), true);
2140 $this->persistent = $this->booly($field->getAttribute('persistent'), false);
2141 $this->autofocus = $this->booly($field->getAttribute('autofocus'), false);
2142 $this->autocomplete = $this->booly($field->getAttribute('autocomplete'), false);
2143 $this->visible = $this->booly($field->getAttribute('visible'), true);
2144 $this->dataset = $field->getAttribute('dataset');
2145 $this->options = array();
2146 if ($this->dataset) {
2147 if ($this->dataset == "institutions") {
2148 $institutions = GrimaDB::getInstitutions();
2149 $currentUser = GrimaUser::GetCurrentUser();
2150 foreach ($institutions as $institution) {
2151 $i = htmlspecialchars($institution);
2152 $s = ($institution === $currentUser['institution']) ? ' selected="selected"' : '';
2153 $this->options[] = "<option value=\"$i\"$s>$i</option>";
2154 }
2155 }
2156 } else {
2157 foreach ($field->getElementsByTagName("option") as $option) {
2158 $this->options[] = $option->ownerDocument->saveXML($option);
2159 }
2160 }
2161 }
static getInstitutions()
Definition: grima-lib.php:4725
booly($str, $default='undefined')
return boolean meaning of common terms ("true","on","1","yes")
Definition: grima-lib.php:2101
static GetCurrentUser()
Definition: grima-lib.php:4930

References booly(), GrimaUser\GetCurrentUser(), and GrimaDB\getInstitutions().

Member Function Documentation

◆ booly()

GrimaFormField::booly (   $str,
  $default = 'undefined' 
)

return boolean meaning of common terms ("true","on","1","yes")

Parameters
string $str term to interpret
$default if it is not found
Returns
boolean true or false

Definition at line 2101 of file grima-lib.php.

2102 {
2103 switch(strtolower($str)) {
2104 case 'true':
2105 case 't':
2106 case 'on':
2107 case 'yes':
2108 case '1':
2109 return true;
2110 case 'false':
2111 case 'f':
2112 case 'off':
2113 case 'no':
2114 case '0':
2115 return false;
2116 default:
2117 return $default;
2118 }
2119 }

Referenced by __construct().

Member Data Documentation

◆ $autocomplete

GrimaFormField::$autocomplete
protected

Definition at line 2088 of file grima-lib.php.

◆ $autofocus

GrimaFormField::$autofocus

Definition at line 2084 of file grima-lib.php.

◆ $dataset

GrimaFormField::$dataset

Definition at line 2087 of file grima-lib.php.

◆ $error_condition

GrimaFormField::$error_condition = ""

Definition at line 2090 of file grima-lib.php.

◆ $error_message

GrimaFormField::$error_message = ""

Definition at line 2091 of file grima-lib.php.

◆ $highlight

GrimaFormField::$highlight
protected

Definition at line 2089 of file grima-lib.php.

◆ $label

GrimaFormField::$label

Definition at line 2080 of file grima-lib.php.

◆ $name

GrimaFormField::$name

Definition at line 2078 of file grima-lib.php.

◆ $persistent

GrimaFormField::$persistent

Definition at line 2083 of file grima-lib.php.

◆ $placeholder

GrimaFormField::$placeholder

Definition at line 2081 of file grima-lib.php.

◆ $required

GrimaFormField::$required

Definition at line 2082 of file grima-lib.php.

◆ $rows

GrimaFormField::$rows

Definition at line 2086 of file grima-lib.php.

◆ $shortname

GrimaFormField::$shortname

Definition at line 2079 of file grima-lib.php.

◆ $value

GrimaFormField::$value

Definition at line 2076 of file grima-lib.php.

◆ $visible

GrimaFormField::$visible

Definition at line 2085 of file grima-lib.php.


The documentation for this class was generated from the following file: