Back to Form class

Method postProcess

public mixed
postProcess
(mixed $data, mixed $group = null)
Method to post-process form data.
Parameters
  • array $data An array of field values to post-process.
  • string $group The optional dot-separated form group path on which to filter the fields to be validated.
Returns
  • mixed Array or false.
Since
  • 4.0.0
Class: Form
Project: Joomla

Method postProcess - Source code

/**
 * Method to post-process form data.
 *
 * @param   array   $data   An array of field values to post-process.
 * @param   string  $group  The optional dot-separated form group path on which to filter the
 *                          fields to be validated.
 *
 * @return  mixed  Array or false.
 *
 * @since   4.0.0
 */
public function postProcess($data, $group = null)
{
    // Make sure there is a valid SimpleXMLElement
    if (!$this->xml instanceof \SimpleXMLElement) {
        throw new \UnexpectedValueException(sprintf('%s::%s `xml` is not an instance of SimpleXMLElement', \get_class($this), __METHOD__));
    }
    $input = new Registry($data);
    $output = new Registry();
    // Get the fields for which to postProcess the data.
    $fields = $this->findFieldsByGroup($group);
    if (!$fields) {
        // PANIC!
        return false;
    }
    // Filter the fields.
    foreach ($fields as $field) {
        $name = (string) $field['name'];
        // Get the field groups for the element.
        $attrs = $field->xpath('ancestor::fields[@name]/@name');
        $groups = array_map('strval', $attrs ?: []);
        $attrGroup = implode('.', $groups);
        $key = $attrGroup ? $attrGroup . '.' . $name : $name;
        // Filter the value if it exists.
        if ($input->exists($key)) {
            $fieldobj = $this->loadField($field, $group);
            $output->set($key, $fieldobj->postProcess($input->get($key, (string) $field['default']), $group, $input));
        }
    }
    return $output->toArray();
}