/** * Set a regex validator for a field. The validator will check if regex is matched on form correct. * * @param Field $field The field * @param string $pattern The pattern to match. This function does not validate given pattern * @param string|null $help_text Optionally set placeholder text for field i.e. DD-MM-YYYY */ public static function validateRegularExpression(\FormHandler\Field\Field $field, $pattern, $help_text = null) { $field->setExtra(' pattern="' . $pattern . '"', true)->setValidator(function ($value) use($pattern) { return is_string($value) && preg_match($pattern, $value); }); if (!is_null($help_text)) { $field->setExtra(' placeholder="' . $help_text . '"', true); } }
/** * Hidden::getValue(); * * Return the value of the field * * @return mixed Value of the field */ public function getValue() { $value = parent::getValue(); if (is_string($value) && substr($value, 0, 11) == '__FH_JSON__') { $value = json_decode(substr($value, 11), true); } return $value; }
public function setValidator($validator = null) { if (count($this->getValidators()) === 0 && $validator instanceof FormHandler\Validator\FunctionCallable && is_array($validator->getCallable())) { $callable = $validator->getCallable(); //detect if it is an optional validator if ($callable[0] instanceof Validator && substr($callable[1], 0, 1) !== '_') { parent::setValidator(new \FormHandler\Validator\NotEmpty()); } } return parent::setValidator(FormHandler::parseValidator($validator, $this)); }
/** * Is field valid * * @return \FormHandler\Field\FileBasic * @author Marien den Besten */ public function processValidators() { $this->setErrorState(false); // when no file field was submitted (on multi-paged forms) if (!isset($_FILES[$this->name])) { return $this; } // is a own error handler used? if (count($this->validators) != 0) { parent::processValidators(); return $this; } // easy name to work with (this is the $_FILES['xxx'] array ) $file = $this->value; if ($this->getRequired() === true && (!is_array($file) || trim($file['name']) == '')) { //no file uploaded $this->setErrorMessage(\FormHandler\Language::get(22)); $this->setErrorState(true); } return $this; }
/** * Set disabled state * * @param boolean $value * @return static * @author Marien den Besten */ public function setDisabled($value = null) { if (is_bool($value) || is_null($value)) { return parent::setDisabled($value); } //convert to array $this->disabled = !is_array($this->disabled) ? array() : $this->disabled; $value_processed = !is_array($value) ? array($value) : $value; $this->disabled = array_merge($this->disabled, $value_processed); return $this; }
public function setDisabled($bool = null) { if (is_array($bool)) { $this->disable_options = $bool; } else { $this->disable_options = null; parent::setDisabled($bool); } return $this; }
/** * Set if the array keys of the options has to be used as values for the field * * @param boolean $mode The mode * @return \FormHandler\Field\SelectList * @author Teye Heimans */ public function useArrayKeyAsValue($mode) { if (!is_null($mode)) { parent::useArrayKeyAsValue($mode); $this->field_on->useArrayKeyAsValue($mode); $this->field_off->useArrayKeyAsValue($mode); } return $this; }
/** * Constructor * * Create a new text field * * @param FormHandler $form The form where this field is located on * @param string $name The name of the field * @return \FormHandler\Field\Text * @author Teye Heimans * @author Marien den Besten */ public function __construct(FormHandler $form, $name) { // call the constructor of the Field class return parent::__construct($form, $name)->setSize(20)->setMaxlength(0); }
/** * Get View value * * @return string * @author Marien den Besten */ public function _getViewValue() { return nl2br(parent::_getViewValue()); }
/** * Set disabled * * @param boolean $bool * @return \FormHandler\Field\Field */ public function setDisabled($bool = true) { $this->empty->setDisabled($bool); $this->unit->setDisabled($bool); $this->temperature->setDisabled($bool); return parent::setDisabled($bool); }
/** * Handle functionality onPost * * Will be called by FormHandler * * @param FormHandler $form * @author Marien den Besten */ public function onPost(FormHandler $form) { parent::onPost($form); $this->button_edit->onPost($form); }
/** * Constructor * * Create a new radio field * * @param object $form The form where this field is located on * @param string $name The name of the field * @param array|string $options The options for the field * @return \FormHandler\Field\Radio * @author Teye Heimans * @author Marien den Besten */ public function __construct(FormHandler $form, $name, $options = array()) { // call the constructor of the Field class return parent::__construct($form, $name)->setOptions($options)->setMask(\FormHandler\Configuration::get('default_glue_mask'))->useArrayKeyAsValue(\FormHandler\Configuration::get('default_usearraykey'))->setFocusName($name . '_1'); }
/** * Get if the field is in error state * * @return boolean * @author Marien den Besten */ public function getErrorState() { $empty_value = $this->empty->getValue(); if ($this->allow_empty === true && !empty($empty_value)) { return false; } return parent::getErrorState(); }