예제 #1
0
 /**
  * Returns the HTML representation of the element
  *
  * The method changes the element's name to foo[bar][] if it was foo[bar]
  * originally. If it is not done, then one of the click coordinates will be
  * lost, see {@link http://bugs.php.net/bug.php?id=745}
  *
  * @return   string
  */
 public function __toString()
 {
     if (false === strpos($this->attributes['name'], '[') || '[]' == substr($this->attributes['name'], -2)) {
         return parent::__toString();
     } else {
         $this->attributes['name'] .= '[]';
         $html = parent::__toString();
         $this->attributes['name'] = substr($this->attributes['name'], 0, -2);
         return $html;
     }
 }
예제 #2
0
 /**
  * Performs the server-side validation
  *
  * Before the Rules added to the element kick in, the element checks the
  * error code added to the $_FILES array by PHP. If the code isn't
  * UPLOAD_ERR_OK or UPLOAD_ERR_NO_FILE then a built-in error message will be
  * displayed and no further validation will take place.
  *
  * @return   boolean     Whether the element is valid
  */
 protected function validate()
 {
     if (strlen($this->error)) {
         return false;
     }
     if (isset($this->value['error']) && !in_array($this->value['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE))) {
         $errorMessage = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('file', $this->value['error']), $this->language) : call_user_func($this->messageProvider, array('file', $this->value['error']), $this->language);
         if (UPLOAD_ERR_INI_SIZE == $this->value['error']) {
             $iniSize = ini_get('upload_max_filesize');
             $size = intval($iniSize);
             switch (strtoupper(substr($iniSize, -1))) {
                 case 'G':
                     $size *= 1024;
                 case 'M':
                     $size *= 1024;
                 case 'K':
                     $size *= 1024;
             }
         } elseif (UPLOAD_ERR_FORM_SIZE == $this->value['error']) {
             foreach ($this->getDataSources() as $ds) {
                 if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
                     $size = intval($ds->getValue('MAX_FILE_SIZE'));
                     break;
                 }
             }
         }
         $this->error = isset($size) ? sprintf($errorMessage, $size) : $errorMessage;
         return false;
     }
     return parent::validate();
 }
예제 #3
0
 public function __construct($name = null, $attributes = null, array $data = array())
 {
     parent::__construct($name, $attributes, $data);
     $this->attributes['type'] = 'concrete';
 }
예제 #4
0
파일: sliiing.php 프로젝트: grlf/eyedock
 public function render(HTML_QuickForm2_Renderer $renderer)
 {
     $renderer->getJavascriptBuilder()->addElementJavascript($this->getJs());
     return parent::render($renderer);
 }
 public function __toString()
 {
     if (0 == strlen($this->data['content'])) {
         $label = '';
     } elseif ($this->frozen) {
         $label = $this->data['content'];
     } else {
         $label = '<label for="' . htmlspecialchars($this->getId(), ENT_QUOTES, self::getOption('charset')) . '">' . $this->data['content'] . '</label>';
     }
     return parent::__toString() . $label;
 }
예제 #6
0
 function setValue($value)
 {
     if (is_array($value)) {
         if ($value['u'] == 'lifetime') {
             $this->period = Am_Period::getLifetime();
         } else {
             if ($value['c'] && $value['u']) {
                 $this->period = new Am_Period($value['c'], $value['u']);
             } else {
                 $this->period = new Am_Period();
             }
         }
     } else {
         $this->period = new Am_Period($value);
     }
     $value = $this->period->__toString();
     parent::setValue($value);
 }
예제 #7
0
 /**
  * Performs the server-side validation.
  * Checks captcha validation first, continues with
  * defined rules if captcha is valid
  *
  * @return boolean Whether the element is valid
  */
 protected function validate()
 {
     // Alternative: use custom rule to get error messages
     if (!$this->verifyCaptcha()) {
         $this->setError($this->data['captchaSolutionWrong']);
         return false;
     }
     return parent::validate();
 }
예제 #8
0
 /**
  * Disallows setting an error message on hidden elements
  *
  * @param string|null $error
  *
  * @return HTML_QuickForm2_Element_InputHidden
  * @throws HTML_QuickForm2_InvalidArgumentException if $error is not empty
  */
 public function setError($error = null)
 {
     if (strlen($error)) {
         throw new HTML_QuickForm2_InvalidArgumentException("Hidden elements cannot have validation errors");
     }
     return parent::setError($error);
 }