/** * Returns if a valid value is supplied. * * Very basic validation. Only checks whether exactly one value is supplied * for a single choice control. */ function is_valid() { $value = $this->get('value'); if (!$this->_get('multiple') && is_null($value)) { $this->set('error', 'Invalid value'); return false; } return parent::is_valid(); }
/** \{ * \name Validation methods */ function is_valid() { /* If this is a single line text input control, we can do some * preliminary checks to see whether the user has tried to mess things * up by now respecting our value restrictions in the html. This will * not result in pretty error messages, but hey, who's trying to fool * who anyway? */ if (!$this->_get('multiline')) { $value = $this->_get('value'); /* Newlines are invalid */ if (str_contains($value, "\n") || str_contains($value, "\r")) { $this->set('valid', false); $this->set('error', 'Invalid newlines'); return false; } /* Check maxlength. FIXME: this likeley does not work correctly with * multibyte UTF-8 characters because of strlen() counting bytes * instead of characters... */ $maxlength = $this->_get('maxlength'); if (!is_null($maxlength) && strlen($value) > $maxlength) { $this->set('valid', false); $this->set('error', 'Too long (probably because of multibyte characters)'); return false; } } /* Now get along with validators and perhaps other validation */ return parent::is_valid(); }
/** \{ * \name Validation methods */ function is_valid() { $fi = $this->get('fileinfo'); if (!is_null($fi)) { $error = $fi['error']; switch ($error) { case UPLOAD_ERR_OK: case UPLOAD_ERR_NO_FILE: $errormsg = ''; break; case UPLOAD_ERR_INI_SIZE: $errormsg = "The uploaded file exceeds the upload_max_filesize directive (" . ini_get("upload_max_filesize") . ") in php.ini."; break; case UPLOAD_ERR_FORM_SIZE: $errormsg = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form."; break; case UPLOAD_ERR_PARTIAL: $errormsg = "The uploaded file was only partially uploaded."; break; case UPLOAD_ERR_NO_TMP_DIR: $errormsg = "Missing a temporary folder."; break; case UPLOAD_ERR_CANT_WRITE: $errormsg = "Failed to write file to disk"; break; default: $errormsg = "Unknown File Error"; } if (strlen($errormsg) > 0) { $this->set('error', $errormsg); $this->set('valid', false); return false; } } /* Now get along with validators and perhaps other validation */ return parent::is_valid(); }
/** * \protected * * Create a new base button. * * This constructor must be called from subclass constructors, e.g. * AnewtFormControlButtonSubmit and AnewtFormControlButtonReset * * \param $name * The name of this control. */ function __construct($name) { parent::__construct($name); $this->_seed(array('input-type' => 'button', 'extra-class' => 'button-normal', 'can-be-filled' => false, 'render-name' => true)); }