protected function filter(ymcHtmlFormInputSource $inputSource) { $array = $inputSource->get($this->name, FILTER_UNSAFE_RAW, FILTER_FORCE_ARRAY); // Workaround since FILTER_FORCE_ARRAY returns NULL instead of array() for no checkbox // set. if (NULL === $array) { $array = array(); } if (!is_array($array)) { $failureClass = $this->options->filterFailure; $this->failures[] = new $failureClass($this); $array = array(); } $value = array(); if (is_array($this->values)) { // Filter by predefined value field foreach ($this->values as $key) { $value[$key] = array_key_exists($key, $array); } } else { // Return all checked checkboxes foreach (array_keys($array) as $key) { $value[$key] = TRUE; } } return $value; }
protected function filter(ymcHtmlFormInputSource $inputSource) { $options = $this->options; $value = $inputSource->get($this->name, $options->filter, $options->filterOptions); if (!in_array($value, $this->values)) { $value = ''; $this->failures[] = new ymcHtmlFormFailureNotInSet($this); } return $value; }
protected function filter(ymcHtmlFormInputSource $inputSource) { $input = $inputSource->get($this->name, FILTER_UNSAFE_RAW); try { return new DateTime($input); } catch (Exception $e) { $failureClass = $this->options->filterFailure; $this->failures[] = new $failureClass($this); } }
public function init(ymcHtmlForm $form, ymcHtmlFormInputSource $inputSource = NULL) { $form->registerOnInit($this); if ($inputSource) { $options = $this->options; $this->value = $inputSource->get($this->name, $options->filter, $options->filterOptions); if ($this->value) { $form->setButton($this); } } return array(); }
/** * Called by init() to do the filtering and validation. * * @param ymcHtmlFormInputSource $inputSource * * @return mixed The filtered value */ protected function filter(ymcHtmlFormInputSource $inputSource) { $options = $this->options; $emptyFailure = $options->emptyFailure; $value = $inputSource->get($this->name, $options->filter, $options->filterOptions); $this->unsafeRawValue = $inputSource->getUnsafeRaw($this->name); $valid = FALSE !== $value; if (!$valid) { $this->failures[] = new $options->filterFailure($this); } elseif ($emptyFailure && empty($value)) { $this->failures[] = new $emptyFailure($this); } return $value; }