00001 <?php
00002
00007 class XFormsSubmitControl extends XFormsControl
00008 {
00009
00010
00011
00012
00013
00014
00022 protected function buildPictcha() {
00023 $p = new Pictcha();
00024 $p->setMaxPictcha(8);
00025 $pbuffer = $p->getPictcha();
00026 $values = $p->getPictchaValue();
00027 $pstring = "Please click on the " . $values[0] . " and then on the " . $values[1]
00028 . ". This will protect us from receiving spam.";
00029 $js = $p->getJavascript();
00030 return array('pictcha' => $pbuffer, 'caption' => $pstring, 'js' => $js);
00031 }
00032
00040 public function generateTK() {
00041
00042 # collect pertinent info such as button caption
00043 $id = $this->getControlId();
00044 $caption = $this->getGroup()->getLabel();
00045 if ($caption == '') $caption = 'Submit';
00046
00047 # create a box for the entire output of pictcha + submit button
00048 $box = new TKVBox();
00049
00050 # PICTCHA
00051 # if we need to show a pictcha at all
00052 if (SConfig::getOption('xforms.pictcha') === true) {
00053 $pictcha = $this->buildPictcha();
00054
00055 # add the caption as a description
00056 $cl = $box->add(new TKLabel($pictcha['caption']));
00057 $cl->class = array('questionDescrip', 'questionDescripTop');
00058
00059 # add the pictcha and javascript to the page
00060 $box->addText($pictcha['pictcha'] . $pictcha['js']);
00061
00062 # see if the pictcha validates or if we need an error message
00063 $ib = $this->getParent();
00064 $xfe = $ib->getValidator()->getErrorCode(
00065 $ib->getParent()->getErrorCode('pictcha'));
00066 if ($xfe != '') {
00067 $errLabel = new TKLabel('↑ ' . $xfe);
00068 $errLabel->class = array('errorMsg');
00069 $box->add($errLabel);
00070 }
00071
00072 # put a spacer after the bottom of the pictcha
00073 $box->addText('<br />');
00074 }
00075
00076 # SUBMIT BUTTON
00077 # add a hidden field to hint that we have submitted
00078
00079
00080 # add the submit button
00081
00082 $cancelLoc = SConfig::getOption('xforms.cancelLocation');
00083 if ($cancelLoc == '')
00084 $cancelLoc = 'javascript:history.back();';
00085 else
00086 $cancelLoc = 'javascript:parent.location=\'' . $cancelLoc . '\'';
00087 if (SConfig::getOption('xforms.cancelButton'))
00088 $cancel = (' <input name="cancel" type="button" value="Cancel"'
00089 . 'onclick="' . $cancelLoc . '" />');
00090 else
00091 $cancel = '';
00092 $box->addText('<input name="submit" type="submit" value="' . $caption . '" />' . $cancel);
00093 return $box;
00094 }
00095
00096 }
00097
00098 ?>