Nette\Forms\Helpers::extractHttpData PHP Method

extractHttpData() public static method

Extracts and sanitizes submitted form data for single control.
public static extractHttpData ( array $data, $htmlName, $type ) : string | string[]
$data array
return string | string[]
    public static function extractHttpData(array $data, $htmlName, $type)
    {
        $name = explode('[', str_replace(['[]', ']', '.'], ['', '', '_'], $htmlName));
        $data = Nette\Utils\Arrays::get($data, $name, NULL);
        $itype = $type & ~Form::DATA_KEYS;
        if (substr($htmlName, -2) === '[]') {
            if (!is_array($data)) {
                return [];
            }
            foreach ($data as $k => $v) {
                $data[$k] = $v = static::sanitize($itype, $v);
                if ($v === NULL) {
                    unset($data[$k]);
                }
            }
            if ($type & Form::DATA_KEYS) {
                return $data;
            }
            return array_values($data);
        } else {
            return static::sanitize($itype, $data);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Returns submitted HTTP data.
  * @return mixed
  */
 public function getHttpData($type = NULL, $htmlName = NULL)
 {
     if ($this->httpData === NULL) {
         if (!$this->isAnchored()) {
             throw new Nette\InvalidStateException('Form is not anchored and therefore can not determine whether it was submitted.');
         }
         $data = $this->receiveHttpData();
         $this->httpData = (array) $data;
         $this->submittedBy = is_array($data);
     }
     if ($htmlName === NULL) {
         return $this->httpData;
     }
     return Helpers::extractHttpData($this->httpData, $htmlName, $type);
 }
All Usage Examples Of Nette\Forms\Helpers::extractHttpData