Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_question_type_password.inc
1 <?php
18 require_once dirname(__FILE__).'/../../form_question/form_question.inc';
19 
20 
33 {
34 
35 
43  function Form_Question_Type_Password($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  $width = $this->attr('width');
73  $max = $this->attr('max');
74  $extras = $this->attr('extra');
75  $name_a = 'q'.$this->id;
76  $name_b = 'q'.$this->id.'_2';
77 
78  // prepare a valid value for the field id
79  $extras_a = $extras.' id="'.str_replace(':', '_', $name_a).'"';
80  $extras_b = $extras.' id="'.str_replace(':', '_', $name_b).'"';
81 
82  if ($this->attr('tabindex')) {
83  $extras_a .= ' tabindex="'.$this->attr('tabindex').'"';
84  $extras_b .= ' tabindex="'.$this->attr('tabindex').'"';
85  }
86 
87  $value = $this->attr('default');
88 
89  ob_start();
90  password_box($name_a, $value, $width, $max, $extras_a);
91  if ($this->attr('verify')) {
92  echo '<br />';
93  password_box($name_b, $value, $width, $max, $extras_b);
94  }
95  $html = ob_get_contents();
96  ob_end_clean();
97 
98  // calling text_box will convert the open and close php tags into their html counter-parts
99  // so we need to convert them back to proper php tags
100 
101  return $html;
102 
103  }//end getHtmlField()
104 
105 
121  function hasValidValue($answer=NULL, $mute_errors=FALSE)
122  {
123  if (is_null($answer)) $answer = $this->getValue();
124 
125  // Only try to check "passwords entered differently" if we've actually
126  // submitted something to the form
127  if ($this->attr('verify') && isset($this->_tmp['verify_value']) && ($answer != $this->_tmp['verify_value'])) {
128  $this->failed_rules[] = translate('core_form_password_entered_differently', $this->attr('name'));
129  }
130  if (strlen($answer) < $this->attr('min')) {
131  $this->failed_rules[] = translate('core_form_password_length_>=', $this->attr('name'), $this->attr('min'));
132  }
133  if (strlen($answer) > $this->attr('max')) {
134  $this->failed_rules[] = translate('core_form_password_length_<=', $this->attr('name'), $this->attr('max'));
135  }
136 
137  if (!empty($this->failed_rules)) return FALSE;
138 
139  return parent::hasValidValue($answer, $mute_errors);
140 
141  }//end hasValidValue()
142 
143 
150  function populate()
151  {
152  $name = 'q'.$this->id;
153 
154  if (isset($_POST[$name])) {
155  $this->setValue($_POST[$name]);
156  if ($this->attr('verify')) {
157  $this->_tmp['verify_value'] = $_POST[$name.'_2'];
158  }
159  }
160  return TRUE;
161 
162  }//end populate()
163 
164 
173  function getXML($answer)
174  {
175  ob_start();
176 
177  // save as a text question for now, we may need a better idea here
178  echo '<text_q id="'.addslashes($this->id).'" name="'.htmlspecialchars($this->attr('name')).'">';
179  echo htmlspecialchars($answer);
180  echo '</text_q>';
181 
182  $contents = ob_get_contents();
183  ob_end_clean();
184 
185  return $contents;
186 
187  }//end getXML()
188 
189 
196  function getSummary()
197  {
198  return '';
199 
200  }//end getSummary()
201 
202 
211  function setValue($value)
212  {
213  $this->value = $value;
214  if ($this->attr('verify')) {
215  $this->_tmp['verify_value'] = $value;
216  }
217 
218  }//end setValue()
219 
220 
227  function isEditable()
228  {
229  return FALSE;
230 
231  }//end isEditable()
232 
233 
240  function getHtmlLabel()
241  {
242  return $this->attr('name');
243 
244  }//end getHtmlLabel()
245 
246 
247 }//end class
248 ?>