public function prompt(&$error = null, $request = null) { if ($request === null) { $request = $_POST; } if (\Sledgehammer\extract_element($request, $this->identifier, $answer)) { // @todo check available options return $answer; } }
public function import(&$error = null, $request = null) { if (\Sledgehammer\extract_element($_GET, $this->parameter, $value)) { $this->current = $value; return $value; } }
public function import(&$error = null, $request = null) { if ($request === null) { $request = $_REQUEST; } $name = $this->getAttribute('name'); if ($name === null) { return; } $required = $this->hasAttribute('required'); if ($required && $this->getAttribute('required') === false) { $required = false; } switch (strtolower($this->getAttribute('type'))) { case 'file': // Import a file upload if ($required) { if (count($_FILES) == 0) { notice('$_FILES is empty, check for <form enctype="multipart/form-data">'); return; } if (array_key_exists($name, $_FILES) == false) { $error = 'MISSING_FILE'; return; } } $file = $_FILES[$name]; // @todo support for multiple files if ($file['error'] === UPLOAD_ERR_OK) { unset($file['error']); } else { $error = 'UPLOAD_FAILED'; $constants = get_defined_constants(); foreach ($constants as $constant => $constant_value) { if (substr($constant, 0, 7) === 'UPLOAD_' && $constant_value === $file['error']) { $error = $constant; break; } } } break; case 'checkbox': $valueAttr = $this->getAttribute('value'); $this->setAttribute('checked', false); if (\Sledgehammer\extract_element($request, $name, $value)) { if ($valueAttr) { $this->setAttribute('checked', $value === $valueAttr); } else { $this->setAttribute('checked', true); } } break; default: if (\Sledgehammer\extract_element($request, $name, $value)) { $this->setAttribute('value', $value); if ($required && $value === '') { $error = 'EMPTY_REQUIRED_FIELD'; } return $value; } if ($required) { $error = 'MISSING_FIELD'; } } return $this->getValue(); }