Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_question_type_text.inc
1 <?php
18 require_once dirname(__FILE__).'/../../form_question/form_question.inc';
19 
20 
33 {
34 
35 
43  function Form_Question_Type_Text($assetid=0, $data=Array())
44  {
45  $this->Form_Question($assetid, $data);
46 
47  }//end constructor
48 
49 
57  function _getAllowedLinks()
58  {
59  return Array();
60 
61  }//end _getAllowedLinks()
62 
63 
70  function getHtmlField()
71  {
72  $height = ($this->attr('height')) ? $this->attr('height') : 1;
73  $width = $this->attr('width');
74  $max = $this->attr('max');
75  $extras = $this->attr('extra');
76  $name = 'q'.$this->id;
77 
78  // prepare a valid value for the field id
79  $extras = $extras.' id="'.str_replace(':', '_', $name).'"';
80 
81  if ($this->attr('tabindex')) {
82  $extras .= ' tabindex="'.$this->attr('tabindex').'"';
83  }
84 
85  $value = $this->getValue();
86 
87  ob_start();
88  if ($height == 1) {
89  text_box($name, $value, $width, $max, FALSE, $extras);
90  } else {
91  text_area($name, $value, $width, $height, $max, $extras);
92  }
93  $html = ob_get_contents();
94  ob_end_clean();
95 
96  // calling text_box will convert the open and close php tags into their html counter-parts
97  // so we need to convert them back to proper php tags
98 
99  return $html;
100 
101  }//end getHtmlField()
102 
103 
119  function hasValidValue($answer=NULL, $mute_errors=FALSE)
120  {
121  if (is_null($answer)) $answer = $this->getValue();
122 
123  if ($this->attr('is_required')) {
124  $req_rule = Array('rule_code' => 'comparison', 'operator' => '!=', 'value' => '');
125  array_push($this->vars['rules']['value'], $req_rule);
126  }
127 
128  $ok = parent::hasValidValue($answer, $mute_errors);
129 
130  if ($this->attr('is_required')) {
131  array_pop($this->vars['rules']['value']);
132  }
133 
134  return $ok;
135 
136  }//end hasValidValue()
137 
138 
149  function generateJSCode()
150  {
151  if ($this->attr('is_required')) {
152  $req_rule = Array('rule_code' => 'comparison', 'operator' => '!=', 'value' => '');
153  array_push($this->vars['rules']['value'], $req_rule);
154  }
155 
156  $code = parent::generateJSCode();
157 
158  if ($this->attr('is_required')) {
159  array_pop($this->vars['rules']['value']);
160  }
161 
162  return $code;
163 
164  }//end generateJSCode()
165 
166 
175  function getAllowedRules()
176  {
177  return Array('regexp', 'comparison', 'numeric', 'found_in', 'contain', 'length', 'email', 'begins_with', 'ends_with');
178 
179  }//end getAllowedRules()
180 
181 
190  function getXML($answer)
191  {
192  ob_start();
193 
194  echo '<text_q id="'.addslashes($this->id).'" name="'.htmlspecialchars($this->attr('name')).'">';
195  echo htmlspecialchars($answer);
196  echo '</text_q>';
197 
198  $contents = ob_get_contents();
199  ob_end_clean();
200 
201  return $contents;
202 
203  }//end getXML()
204 
205 
206 }//end class
207 ?>