public function validateAsSubForm(Dictionary $arguments, Dictionary $files)
    {
        $name = $this->name;
        if (!$arguments->has($name, Type::ARRAY))
        {
            $this->errors = [];
            if ($this->isRequired())
            {
                $this->errors = ['' => ['msg' => "{name} is required", 'context' => ['name' => $name]]];
                $this->complete = false;
            }
            return $this->complete;
        }

        $sub = $arguments->get($name);
        $subfiles = $files->has($name, Type::ARRAY) ? $files[$name] : new Dictionary;

        if (!$this->repeatable)
            return $this->validate($sub, $subfiles);

        // Repeatable forms should be an array of arrays - each containing
        // their own set of the values for the form elements. We need to
        // collect them all here.
        $value = [];
        $errors = [];

        // Only numeric keys are allowed for repeatable forms.
        if (!WF::is_numeric_array($sub))
        {
            $this->errors = ['' => ['msg' => "{name} should be an array", 'context' => ['name' => $name]]];
            $this->complete = false;
            return $this->complete;
        }

        // Validate each set of submitted data
        $valid = true;
        foreach ($sub as $idx => $subsub)
        {
            $subsubfiles = $subfiles->has($idx, Type::ARRAY) ? $subfiles[$idx] : new Dictionary;
            $valid = $valid && $this->validate($subsub, $subsubfiles);
            $subvalue = $this->getValue();
            $value[$idx] = $subvalue;

            if (count($this->errors))
                $errors[$idx] = $this->errors;
        }

        // Store the value and the errors for the form as a whole.
        $this->value = $value;
        $this->errors = $errors;
        return $valid;
    }
public function validateAsSubForm(Dictionary $arguments, Dictionary $files)
    {
        $name = $this->name;
        if (!$arguments->has($name, Type::ARRAY))
        {
            $this->errors = [];
            if ($this->isRequired())
            {
                $this->errors = ['' => ['msg' => "{name} is required", 'context' => ['name' => $name]]];
                $this->complete = false;
            }
            return $this->complete;
        }

        $sub = $arguments->get($name);
        $subfiles = $files->has($name, Type::ARRAY) ? $files[$name] : new Dictionary;

        if (!$this->repeatable)
            return $this->validate($sub, $subfiles);

        // Repeatable forms should be an array of arrays - each containing
        // their own set of the values for the form elements. We need to
        // collect them all here.
        $value = [];
        $errors = [];

        // Only numeric keys are allowed for repeatable forms.
        if (!WF::is_numeric_array($sub))
        {
            $this->errors = ['' => ['msg' => "{name} should be an array", 'context' => ['name' => $name]]];
            $this->complete = false;
            return $this->complete;
        }

        // Validate each set of submitted data
        $valid = true;
        foreach ($sub as $idx => $subsub)
        {
            $subsubfiles = $subfiles->has($idx, Type::ARRAY) ? $subfiles[$idx] : new Dictionary;
            $valid = $valid && $this->validate($subsub, $subsubfiles);
            $subvalue = $this->getValue();
            $value[$idx] = $subvalue;

            if (count($this->errors))
                $errors[$idx] = $this->errors;
        }

        // Store the value and the errors for the form as a whole.
        $this->value = $value;
        $this->errors = $errors;
        return $valid;
    }
public function validateAsSubForm ( Dictionary $ arguments , Dictionary $ files ) { $ name = $ this -> name ; if ( ! $ arguments -> has ( $ name , Type :: ARRAY ) ) { $ this -> errors = [ ] ; if ( $ this -> isRequired ( ) ) { $ this -> errors = [ '' => [ 'msg' => "{name} is required" , 'context' => [ 'name' => $ name ] ] ] ; $ this -> complete = false ; } return $ this -> complete ; } $ sub = $ arguments -> get ( $ name ) ; $ subfiles = $ files -> has ( $ name , Type :: ARRAY ) ? $ files [ $ name ] : new Dictionary ; if ( ! $ this -> repeatable ) return $ this -> validate ( $ sub , $ subfiles ) ; // Repeatable forms should be an array of arrays - each containing // their own set of the values for the form elements. We need to // collect them all here. $ value = [ ] ; $ errors = [ ] ; // Only numeric keys are allowed for repeatable forms. if ( ! WF :: is_numeric_array ( $ sub ) ) { $ this -> errors = [ '' => [ 'msg' => "{name} should be an array" , 'context' => [ 'name' => $ name ] ] ] ; $ this -> complete = false ; return $ this -> complete ; } // Validate each set of submitted data $ valid = true ; foreach ( $ sub as $ idx => $ subsub ) { $ subsubfiles = $ subfiles -> has ( $ idx , Type :: ARRAY ) ? $ subfiles [ $ idx ] : new Dictionary ; $ valid = $ valid && $ this -> validate ( $ subsub , $ subsubfiles ) ; $ subvalue = $ this -> getValue ( ) ; $ value [ $ idx ] = $ subvalue ; if ( count ( $ this -> errors ) ) $ errors [ $ idx ] = $ this -> errors ; } // Store the value and the errors for the form as a whole. $ this -> value = $ value ; $ this -> errors = $ errors ; return $ valid ; }
Validate the form as a sub form

@param Dictionary $arguments The submitted data
@param Dictionary $files The submitted files
@return True if the form valides, false if not.
Validate the form as a sub form