ddb10a84c38204725eb9dcf56f6fac23fa336e9d
[shipsimu.git] / inc / classes / main / helper / web / class_WebFormHelper.php
1 <?php
2 /**
3  * A helper for constructing web forms
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class WebFormHelper extends BaseHelper {
25         /**
26          * Instance to the class which provides field values
27          */
28         private $valueInstance = null;
29
30         /**
31          * Wether the form tag is opened (keep at false or else your forms will
32          * never work!)
33          */
34         private $formOpened = false;
35
36         /**
37          * Name of the form
38          */
39         private $formName = "";
40
41         /**
42          * Wether the group is opened or not
43          */
44         private $groupOpened = false;
45
46         /**
47          * Wether the sub group is opened or not
48          */
49         private $subGroupOpened = false;
50
51         /**
52          * Name of the sub group
53          */
54         private $subGroupName = "";
55
56         // Class Constants
57         const EXCEPTION_FORM_NAME_INVALID       = 0x030;
58         const EXCEPTION_CLOSED_FORM             = 0x031;
59         const EXCEPTION_OPENED_FORM             = 0x032;
60         const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x033;
61
62         /**
63          * Protected constructor
64          *
65          * @return      void
66          */
67         protected function __construct () {
68                 // Call parent constructor
69                 parent::__construct(__CLASS__);
70
71                 // Set part description
72                 $this->setObjectDescription("Helper class for HTML forms");
73
74                 // Create unique ID number
75                 $this->generateUniqueId();
76         }
77
78         /**
79          * Creates the helper class with the given template engine instance and form name
80          *
81          * @param       $templateInstance       An instance of a valid template engine
82          * @param       $formName                       Name of the form
83          * @param       $formId                         Value for "id" attribute (default: $formName)
84          * @return      $helperInstance         A preparedf instance of this class
85          */
86         public final static function createWebFormHelper (CompileableTemplate $templateInstance, $formName, $formId = false) {
87                 // Get new instance
88                 $helperInstance = new WebFormHelper();
89
90                 // Set template instance
91                 $helperInstance->setTemplateInstance($templateInstance);
92
93                 // Is the form id not set?
94                 if ($formId === false) {
95                         // Use form id from form name
96                         $formId = $formName;
97                 }
98
99                 // Create the form
100                 $helperInstance->addFormTag($formName, $formId);
101
102                 // Return the prepared instance
103                 return $helperInstance;
104         }
105
106         /**
107          * Pre-fetches field default values from the given registry key instance into this class
108          *
109          * @param       $registryKey
110          * @return      void
111          * @throws      NullPointerException    If an instance from registry is null
112          */
113         public function prefetchFieldValues ($registryKey) {
114                 // Get the required instance
115                 $this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
116
117                 // Is the instance valid?
118                 if (is_null($this->valueInstance)) {
119                         // Throw an exception
120                         throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
121                 } // END - if
122         }
123
124         /**
125          * Add the form tag or close it an already opened form tag
126          *
127          * @param       $formName       Name of the form (default: false)
128          * @param       $formId         Id of the form (attribute "id"; default: false)
129          * @return      void
130          * @throws      InvalidFormNameException        If the form name is invalid (=false)
131          * @todo        Add some unique PIN here to bypass problems with some browser and/or extensions
132          */
133         public function addFormTag ($formName = false, $formId = false) {
134                 // When the form is not yet opened at least form name must be valid
135                 if (($this->formOpened === false) && ($formName === false)) {
136                         // Thrown an exception
137                         throw new InvalidFormNameException ($this, self::EXCEPTION_FORM_NAME_INVALID);
138                 } // END - if
139
140                 // Close the form is default
141                 $formContent = "</form>";
142
143                 // Check wether we shall open or close the form
144                 if ($this->formOpened === false) {
145                         // Add HTML code
146                         $formContent = sprintf("<form name=\"%s\" class=\"forms\" action=\"%s/%s\" method=\"%s\" target=\"%s\"",
147                                 $formName,
148                                 $this->getConfigInstance()->readConfig('base_url'),
149                                 $this->getConfigInstance()->readConfig('form_action'),
150                                 $this->getConfigInstance()->readConfig('form_method'),
151                                 $this->getConfigInstance()->readConfig('form_target')
152                         );
153
154                         // Is the form id set?
155                         if ($formId !== false) {
156                                 // Then add it as well
157                                 $formContent .= sprintf(" id=\"%s_form\"",
158                                         $formId
159                                 );
160                         }
161
162                         // Add close bracket
163                         $formContent .= ">";
164
165                         // Open the form and remeber the form name
166                         $this->formOpened = true;
167                         $this->formName = $formName;
168                 } else {
169                         // Add the hidden field required to identify safely this form
170                         $this->addInputHiddenField('form', $this->formName);
171
172                         // Is a group open?
173                         if ($this->groupOpened === true) {
174                                 // Then automatically close it here
175                                 $this->addFormGroup("", "");
176                         } // END - if
177
178                         // Simply close it
179                         $this->formOpened = false;
180                 }
181
182                 // Add it to the content
183                 $this->addContent($formContent);
184         }
185
186         /**
187          * Add a text input tag to the form or throw an exception if it is not yet
188          * opened. The field's name will be set as id.
189          *
190          * @param       $fieldName              Input field name
191          * @param       $fieldValue             Input default value (default: empty)
192          * @return      void
193          * @throws      FormClosedException             If the form is not yet opened
194          */
195         public function addInputTextField ($fieldName, $fieldValue = "") {
196                 // Is the form opened?
197                 if ($this->formOpened === false) {
198                         // Throw an exception
199                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
200                 } // END - if
201
202                 // Generate the content
203                 $inputContent = sprintf("<input type=\"text\" class=\"textfield\" id=\"%s_field\" name=\"%s\" value=\"%s\" />",
204                         $fieldName,
205                         $fieldName,
206                         $fieldValue
207                 );
208
209                 // And add it maybe with a "li" tag
210                 $this->addContent($inputContent);
211         }
212
213         /**
214          * Add a text input tag to the form with pre-loaded default value
215          *
216          * @param       $fieldName      Input field name
217          * @return      void
218          */
219         public function addInputTextFieldWithDefault ($fieldName) {
220                 // Get the value from instance
221                 $fieldValue = $this->getField($fieldName);
222                 //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
223
224                 // Add the text field
225                 $this->addInputTextField($fieldName, $fieldValue);
226         }
227
228         /**
229          * Add a password input tag to the form or throw an exception if it is not
230          * yet opened. The field's name will be set as id.
231          *
232          * @param       $fieldName                      Input field name
233          * @param       $fieldValue                     Input default value (default: empty)
234          * @return      void
235          * @throws      FormClosedException             If the form is not yet opened
236          */
237         public function addInputPasswordField ($fieldName, $fieldValue = "") {
238                 // Is the form opened?
239                 if ($this->formOpened === false) {
240                         // Throw an exception
241                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
242                 } // END - if
243
244                 // Generate the content
245                 $inputContent = sprintf("<input type=\"password\" class=\"password\" id=\"%s_field\" name=\"%s\" value=\"%s\" />",
246                         $fieldName,
247                         $fieldName,
248                         $fieldValue
249                 );
250
251                 // And add it
252                 $this->addContent($inputContent);
253         }
254
255         /**
256          * Add a hidden input tag to the form or throw an exception if it is not
257          * yet opened. The field's name will be set as id.
258          *
259          * @param       $fieldName                      Input field name
260          * @param       $fieldValue                     Input default value (default: empty)
261          * @return      void
262          * @throws      FormClosedException             If the form is not yet opened
263          */
264         public function addInputHiddenField ($fieldName, $fieldValue = "") {
265                 // Is the form opened?
266                 if ($this->formOpened === false) {
267                         // Throw an exception
268                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
269                 } // END - if
270
271                 // Generate the content
272                 $inputContent = sprintf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />",
273                         $fieldName,
274                         $fieldValue
275                 );
276
277                 // And add it
278                 $this->addContent($inputContent);
279         }
280
281         /**
282          * Add a hidden input tag to the form with pre-loaded default value
283          *
284          * @param       $fieldName      Input field name
285          * @return      void
286          */
287         public function addInputHiddenFieldWithDefault ($fieldName) {
288                 // Get the value from instance
289                 $fieldValue = $this->getField($fieldName);
290                 //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
291
292                 // Add the text field
293                 $this->addInputHiddenField($fieldName, $fieldValue);
294         }
295
296         /**
297          * Add a hidden input tag to the form with configuration value
298          *
299          * @param       $fieldName      Input field name
300          * @param       $prefix         Prefix for configuration without trailing _
301          * @return      void
302          */
303         public function addInputHiddenConfiguredField ($fieldName, $prefix) {
304                 // Get the value from instance
305                 $fieldValue = $this->getConfigInstance()->readConfig("{$prefix}_{$fieldName}");
306                 //* DEBUG: */ echo __METHOD__.":".$fieldName."=".$fieldValue."<br />\n";
307
308                 // Add the text field
309                 $this->addInputHiddenField($fieldName, $fieldValue);
310         }
311
312         /**
313          * Add a checkbox input tag to the form or throw an exception if it is not
314          * yet opened. The field's name will be set as id.
315          *
316          * @param       $fieldName                      Input field name
317          * @param       $fieldChecked           Wether the field is checked (defaut: checked)
318          * @return      void
319          * @throws      FormClosedException             If the form is not yet opened
320          */
321         public function addInputCheckboxField ($fieldName, $fieldChecked = true) {
322                 // Is the form opened?
323                 if ($this->formOpened === false) {
324                         // Throw an exception
325                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
326                 } // END - if
327
328                 // Set wether the check box is checked...
329                 $checked = " checked=\"checked\"";
330                 if ($fieldChecked === false) $checked = " ";
331
332                 // Generate the content
333                 $inputContent = sprintf("<input type=\"checkbox\" name=\"%s\" class=\"checkbox\" id=\"%s_field\" value=\"1\"%s/>",
334                         $fieldName,
335                         $fieldName,
336                         $checked
337                 );
338
339                 // And add it
340                 $this->addContent($inputContent);
341         }
342
343         /**
344          * Add a reset input tag to the form or throw an exception if it is not
345          * yet opened. The field's name will be set as id.
346          *
347          * @param       $buttonText             Text displayed on the button
348          * @return      void
349          * @throws      FormClosedException             If the form is not yet opened
350          */
351         public function addInputResetButton ($buttonText) {
352                 // Is the form opened?
353                 if ($this->formOpened === false) {
354                         // Throw an exception
355                         throw new FormClosedException (array($this, "reset"), self::EXCEPTION_CLOSED_FORM);
356                 } // END - if
357
358                 // Generate the content
359                 $inputContent = sprintf("<input type=\"reset\" class=\"reset_button\" id=\"%s_reset\" value=\"%s\" />",
360                         $this->formName,
361                         $buttonText
362                 );
363
364                 // And add it
365                 $this->addContent($inputContent);
366         }
367
368         /**
369          * Add a reset input tag to the form or throw an exception if it is not
370          * yet opened. The field's name will be set as id.
371          *
372          * @param       $buttonText                     Text displayed on the button
373          * @return      void
374          * @throws      FormClosedException             If the form is not yet opened
375          */
376         public function addInputSubmitButton ($buttonText) {
377                 // Is the form opened?
378                 if ($this->formOpened === false) {
379                         // Throw an exception
380                         throw new FormClosedException (array($this, "submit"), self::EXCEPTION_CLOSED_FORM);
381                 } // END - if
382
383                 // Generate the content
384                 $inputContent = sprintf("<input type=\"submit\" class=\"submit_button\" id=\"%s_submit\" name=\"%s_button\" value=\"%s\" />",
385                         $this->formName,
386                         $this->formName,
387                         $buttonText
388                 );
389
390                 // And add it
391                 $this->addContent($inputContent);
392         }
393
394         /**
395          * Add a form group or close an already opened and open a new one
396          *
397          * @param       $groupName      Name of the group
398          * @param       $groupText      Text including HTML to show above this group
399          * @return      void
400          * @throws      FormClosedException             If no form has been opened before
401          * @throws      EmptyVariableException  If $groupName is not set
402          */
403         public function addFormGroup ($groupName, $groupText) {
404                 // Is a form opened?
405                 if ($this->formOpened === false) {
406                         // Throw exception here
407                         throw new FormClosedException(array($this, $groupName), self::EXCEPTION_CLOSED_FORM);
408                 } // END - if
409
410                 // At least the group name should be set
411                 if ((empty($groupName)) && ($this->groupOpened === false)) {
412                         // Throw exception here
413                         throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
414                 } // END - if
415
416                 // Initialize content with closing div by default
417                 $content = "    </div>\n</div><!-- Group - CLOSE //-->";
418
419                 // Is this group opened?
420                 if ($this->groupOpened === false) {
421                         // Begin the div/span blocks
422                         $content = sprintf("<!-- Group %s - OPEN //-->
423 <div class=\"group_box\" id=\"%s_group_box\">
424         <span class=\"group_text\" id=\"%s_group_text\">
425                 %s
426         </span>
427         <div class=\"group_field\" id=\"%s_group_field\">",
428                                 $groupName,
429                                 $groupName,
430                                 $groupName,
431                                 $groupText,
432                                 $groupName
433                         );
434
435                         // Add the content
436                         $this->addContent($content);
437
438                         // Switch the state
439                         $this->groupOpened = true;
440                 } else {
441                         // Is a sub group opened?
442                         if ($this->subGroupOpened === true) {
443                                 // Close it here
444                                 $this->addFormSubGroup("", "");
445                         } // END - if
446
447                         // Add the content
448                         $this->addContent($content);
449
450                         // Switch the state
451                         $this->groupOpened = false;
452
453                         // All call it again if the group name is not empty
454                         if (!empty($groupName)) {
455                                 $this->addFormGroup($groupName, $groupText);
456                         } // END - if
457                 }
458         }
459
460         /**
461          * Add a form sub group or close an already opened and open a new one or
462          * throws an exception if no group has been opened before or if the sub
463          * group name is empty.
464          *
465          * @param       $subGroupName   Name of the group
466          * @param       $subGroupText   Text including HTML to show above this group
467          * @return      void
468          * @throws      FormGroupClosedException        If no group has been opened before
469          * @throws      EmptyVariableException          If $subGroupName is not set
470          */
471         public function addFormSubGroup ($subGroupName, $subGroupText) {
472                 // Is a group opened?
473                 if ($this->groupOpened === false) {
474                         // Throw exception here
475                         throw new FormGroupClosedException(array($this, $subGroupName), self::EXCEPTION_UNEXPECTED_CLOSED_GROUP);
476                 } // END - if
477
478                 // At least the sub group name should be set
479                 if ((empty($subGroupName)) && ($this->subGroupOpened === false)) {
480                         // Throw exception here
481                         throw new EmptyVariableException(array($this, 'groupName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
482                 } // END - if
483
484                 // Initialize content with closing div by default
485                 $content = "    </div>\n</div><!-- Sub group- CLOSE //-->";
486
487                 // Is this group opened?
488                 if ($this->subGroupOpened === false) {
489                         // Begin the span block
490                         $content = sprintf("<!-- Sub group %s - OPEN //-->
491 <div class=\"subgroup_box\" id=\"%s_subgroup_box\">
492         <span class=\"subgroup_text\" id=\"%s_subgroup_text\">
493                 %s
494         </span>
495         <div class=\"subgroup_field\" id=\"%s_subgroup_field\">",
496                                 $subGroupName,
497                                 $subGroupName,
498                                 $subGroupName,
499                                 $subGroupText,
500                                 $subGroupName
501                         );
502
503                         // Add the content
504                         $this->addContent($content);
505
506                         // Switch the state and remeber the name
507                         $this->subGroupOpened = true;
508                         $this->subGroupName = $subGroupName;
509                 } else {
510                         // Add the content
511                         $this->addContent($content);
512
513                         // Switch the state
514                         $this->subGroupOpened = false;
515
516                         // All call it again if sub group name is not empty
517                         if (!empty($subGroupName)) {
518                                 $this->addFormSubGroup($subGroupName, $subGroupText);
519                         } // END - if
520                 }
521         }
522
523         /**
524          * Add text surrounded by a span block when there is a group opened before
525          * or else by a div block.
526          *
527          * @param       $fieldName                      Field name
528          * @param       $fieldText                      Text for the field
529          * @return      void
530          * @throws      FormClosedException             If the form is not yet opened
531          */
532         public function addFieldText ($fieldName, $fieldText) {
533                 // Is the form opened?
534                 if ($this->formOpened === false) {
535                         // Throw an exception
536                         throw new FormClosedException (array($this, $fieldName), self::EXCEPTION_CLOSED_FORM);
537                 } // END - if
538
539                 // Set the block type
540                 $block = "div";
541                 if ($this->groupOpened === true) $block = "span";
542
543                 // Generate the content
544                 $inputContent = sprintf("       <%s id=\"%s_text\">
545                 %s
546         </%s>",
547                         $block,
548                         $fieldName,
549                         $fieldText,
550                         $block
551                 );
552
553                 // And add it
554                 $this->addContent($inputContent);
555         }
556
557         /**
558          * Add text (notes) surrounded by a div block. Still opened groups or sub
559          * groups will be automatically closed.
560          *
561          * @param       $formNotes      The form notes we shell addd
562          * @return      void
563          * @throws      FormClosedException             If the form is not yet opened
564          */
565         public function addFormNote ($formNotes) {
566                 // Is the form opened?
567                 if ($this->formOpened === false) {
568                         // Throw an exception
569                         throw new FormClosedException (array($this, "form_notes"), self::EXCEPTION_CLOSED_FORM);
570                 } // END - if
571
572                 // Is a group open?
573                 if ($this->groupOpened === true) {
574                         // Then automatically close it here
575                         $this->addFormGroup("", "");
576                 } // END - if
577
578                 // Generate the content
579                 $inputContent = sprintf("       <div id=\"form_note\">
580                 %s
581         </div>",
582                         $formNotes
583                 );
584
585                 // And add it
586                 $this->addContent($inputContent);
587         }
588
589         /**
590          * Checks wether the registration requires a valid email address
591          *
592          * @return      $required       Wether the email address is required
593          */
594         public function ifRegisterRequiresEmailVerification () {
595                 $required = ($this->getConfigInstance()->readConfig('register_requires_email') == "Y");
596                 return $required;
597         }
598
599         /**
600          * Checks wether profile data shall be asked
601          *
602          * @return      $required       Wether profile shall be asked
603          */
604         public function ifRegisterIncludesProfile () {
605                 $required = ($this->getConfigInstance()->readConfig('register_includes_profile') == "Y");
606                 return $required;
607         }
608
609         /**
610          * Checks wether personal data shall be asked
611          *
612          * @return      $required       Wether personal data shall be asked
613          */
614         public function ifRegisterIncludesPersonaData () {
615                 $required = ($this->getConfigInstance()->readConfig('register_personal_data') == "Y");
616                 return $required;
617         }
618
619         /**
620          * Checks wether email addresses can only be once used
621          *
622          * @return      $isUnique
623          */
624         public function ifEmailMustBeUnique () {
625                 $isUnique = ($this->getConfigInstance()->readConfig('register_email_unique') == "Y");
626                 return $isUnique;
627         }
628
629         /**
630          * Checks wether the specified chat protocol is enabled in this form
631          *
632          * @return      $required       Wether the specified chat protocol is enabled
633          */
634         public function ifChatEnabled ($chatProtocol) {
635                 $required = ($this->getConfigInstance()->readConfig(sprintf("chat_enabled_%s", $chatProtocol)) == "Y");
636                 return $required;
637         }
638
639         /**
640          * Checks wether login is enabled or disabled
641          *
642          * @return      $isEnabled      Wether the login is enabled or disabled
643          */
644         public function ifLoginIsEnabled () {
645                 $isEnabled = ($this->getConfigInstance()->readConfig('login_enabled') == "Y");
646                 return $isEnabled;
647         }
648
649         /**
650          * Checks wether login shall be done by username
651          *
652          * @return      $isEnabled      Wether the login shall be done by username
653          */
654         public function ifLoginWithUsername () {
655                 $isEnabled = ($this->getConfigInstance()->readConfig('login_type') == "username");
656                 return $isEnabled;
657         }
658
659         /**
660          * Checks wether login shall be done by email
661          *
662          * @return      $isEnabled      Wether the login shall be done by email
663          */
664         public function ifLoginWithEmail () {
665                 $isEnabled = ($this->getConfigInstance()->readConfig('login_type') == "email");
666                 return $isEnabled;
667         }
668
669         /**
670          * Checks wether guest login is allowed
671          *
672          * @return      $isAllowed      Wether guest login is allowed
673          */
674         public function ifGuestLoginAllowed () {
675                 $isAllowed = ($this->getConfigInstance()->readConfig('guest_login_allowed') == "Y");
676                 return $isAllowed;
677         }
678
679         /**
680          * Checks wether the email address change must be confirmed
681          *
682          * @return      $requireConfirm         Wether email change must be confirmed
683          */
684         public function ifEmailChangeRequireConfirmation () {
685                 $requireConfirm = ($this->getConfigInstance()->readConfig('email_change_confirmation') == "Y");
686                 return $requireConfirm;
687         }
688
689         /**
690          * Checks wether the rules has been updated
691          *
692          * @return      $rulesUpdated   Wether rules has been updated
693          * @todo        Implement check if rules have been changed
694          */
695         public function ifRulesHaveChanged () {
696                 return false;
697         }
698
699         /**
700          * Checks wether email change is allowed
701          *
702          * @return      $emailChange    Wether changing email address is allowed
703          */
704         public function ifEmailChangeAllowed () {
705                 $emailChange = ($this->getConfigInstance()->readConfig('email_change_allowed') == "Y");
706                 return $emailChange;
707         }
708
709         /**
710          * Checks wether the user account is unconfirmed
711          *
712          * @return      $isUnconfirmed  Wether the user account is unconfirmed
713          */
714         public function ifUserAccountUnconfirmed () {
715                 $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_unconfirmed'));
716                 return $isUnconfirmed;
717         }
718
719         /**
720          * Checks wether the user account is locked
721          *
722          * @return      $isUnconfirmed  Wether the user account is locked
723          */
724         public function ifUserAccountLocked () {
725                 $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_locked'));
726                 return $isUnconfirmed;
727         }
728
729         /**
730          * Checks wether the user account is a guest
731          *
732          * @return      $isUnconfirmed  Wether the user account is a guest
733          */
734         public function ifUserAccountGuest () {
735                 $isUnconfirmed = ($this->getField('user_status') === $this->getConfigInstance()->readConfig('user_status_guest'));
736                 return $isUnconfirmed;
737         }
738
739         /**
740          * Checks wether this form is secured by a CAPTCHA
741          *
742          * @return      $isSecured      Wether this form is secured by a CAPTCHA
743          */
744         public function ifFormSecuredWithCaptcha () {
745                 $isSecured = ($this->getConfigInstance()->readConfig($this->formName."_captcha_secured") == "Y");
746                 return $isSecured;
747         }
748
749         /**
750          * Flushs the content out (not yet secured against open forms, etc.!) or
751          * close the form automatically
752          *
753          * @return      void
754          * @throws      FormOpenedException             If the form is still open
755          */
756         public function flushContent () {
757                 // Is the form still open?
758                 if ($this->formOpened === true) {
759                         // Close the form automatically
760                         $this->addFormTag();
761                 } // END - if
762
763                 // Send content to template engine
764                 $this->getTemplateInstance()->assignVariable($this->formName, $this->getContent());
765         }
766
767         /**
768          * Getter for direct field values
769          *
770          * @param       $fieldName              Name of the field we shall fetch
771          * @return      $fieldValue             Value from field
772          */
773         public function getField ($fieldName) {
774                 // Get the field value
775                 $fieldValue = call_user_func_array(array($this->valueInstance, 'getField'), array($fieldName));
776
777                 // Return it
778                 return $fieldValue;
779         }
780
781         /**
782          * Adds a pre-configured CAPTCHA
783          *
784          * @return      void
785          */
786         public function addCaptcha () {
787                 // Get last executed pre filter
788                 $extraInstance = Registry::getRegistry()->getInstance('extra');
789
790                 // Get a configured instance
791                 $captchaInstance = ObjectFactory::createObjectByConfiguredName("{$this->formName}_captcha", array($this->getTemplateInstance(), $extraInstance));
792
793                 // Initiate the CAPTCHA
794                 $captchaInstance->initiateCaptcha();
795
796                 // Render the CAPTCHA code
797                 $captchaInstance->renderCode();
798
799                 // Get the content and add it to the helper
800                 $this->addContent($captchaInstance->getContent());
801         }
802 }
803
804 // [EOF]
805 ?>