Exemplo n.º 1
0
 /**
  * Implements the onAfterAppend method from the ui_element class.
  *
  * @author Christian Achatz, Stephan Spiess
  * @version
  * Version 0.1, 20.06.2008<br />
  * Version 0.2, 10.11.2008 (Added the "clearonerror" attribute. If set to "true", the field is cleared on error.)<br />
  * Version 0.3, 04.01.2010 (Added the text_id attribute)<br />
  * Version 0.4, 29.10.2012 (Bug-fix: attribute valmarkerclass is now applied to the inner form field to allow css field validation on error)<br />
  */
 public function onParseTime()
 {
     // create text field
     $this->textField = new TextFieldTag();
     $this->textField->setObjectId(XmlParser::generateUniqID());
     // prepare the text field
     $textClass = $this->getAttribute('text_class');
     if ($textClass !== null) {
         $this->textField->setAttribute('class', $textClass);
     }
     $textStyle = $this->getAttribute('text_style');
     if ($textStyle !== null) {
         $this->textField->setAttribute('style', $textStyle);
     }
     $textId = $this->getAttribute('text_id');
     if ($textId !== null) {
         $this->textField->setAttribute('id', $textId);
     }
     // apply validation marker css class to provide validation markup capabilities
     $errorClass = $this->getAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE);
     if ($errorClass !== null) {
         $this->textField->setAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE, $errorClass);
     }
     $this->textFieldName = md5($this->getParentObject()->getAttribute('name') . '_captcha');
     $this->textField->setAttribute('name', $this->textFieldName);
     $this->textField->setAttribute('maxlength', '5');
     // apply the onParseTime method to guarantee native APF environment
     $this->textField->setLanguage($this->language);
     $this->textField->setContext($this->context);
     $this->textField->onParseTime();
     // apply the onAfterAppend method to guarantee native APF environment
     $this->textField->setParentObject($this->getParentObject());
     $this->textField->onAfterAppend();
     // get the captcha string from session
     $session = $this->getRequest()->getSession(ShowCaptchaImageAction::SESSION_NAMESPACE);
     $this->captchaString = $session->load($this->textFieldName);
     $session->save($this->textFieldName, StringAssistant::generateCaptchaString(5));
 }