Contao\Input::post PHP Method

post() public static method

Return a $_POST variable
public static post ( string $strKey, boolean $blnDecodeEntities = false ) : mixed
$strKey string The variable name
$blnDecodeEntities boolean If true, all entities will be decoded
return mixed The cleaned variable value
    public static function post($strKey, $blnDecodeEntities = false)
    {
        $strCacheKey = $blnDecodeEntities ? 'postDecoded' : 'postEncoded';
        if (!isset(static::$arrCache[$strCacheKey][$strKey])) {
            $varValue = static::findPost($strKey);
            if ($varValue === null) {
                return $varValue;
            }
            $varValue = static::decodeEntities($varValue);
            $varValue = static::xssClean($varValue, true);
            $varValue = static::stripTags($varValue);
            if (!$blnDecodeEntities) {
                $varValue = static::encodeSpecialChars($varValue);
            }
            if (TL_MODE != 'BE') {
                $varValue = static::encodeInsertTags($varValue);
            }
            static::$arrCache[$strCacheKey][$strKey] = $varValue;
        }
        return static::$arrCache[$strCacheKey][$strKey];
    }

Usage Example

 /**
  * Run the controller and parse the template
  *
  * @return Response
  */
 public function run()
 {
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_preview');
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['fePreview']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->site = \Input::get('site', true);
     $objTemplate->switchHref = \System::getContainer()->get('router')->generate('contao_backend_switch');
     if (\Input::get('url')) {
         $objTemplate->url = \Environment::get('base') . \Input::get('url');
     } elseif (\Input::get('page')) {
         $objTemplate->url = $this->redirectToFrontendPage(\Input::get('page'), \Input::get('article'), true);
     } else {
         $objTemplate->url = \System::getContainer()->get('router')->generate('contao_root', [], UrlGeneratorInterface::ABSOLUTE_URL);
     }
     // Switch to a particular member (see #6546)
     if (\Input::get('user') && $this->User->isAdmin) {
         $objUser = \MemberModel::findByUsername(\Input::get('user'));
         if ($objUser !== null) {
             $strHash = $this->getSessionHash('FE_USER_AUTH');
             // Remove old sessions
             $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute(time() - \Config::get('sessionTimeout'), $strHash);
             // Insert the new session
             $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute($objUser->id, time(), 'FE_USER_AUTH', \System::getContainer()->get('session')->getId(), \Environment::get('ip'), $strHash);
             // Set the cookie
             $this->setCookie('FE_USER_AUTH', $strHash, time() + \Config::get('sessionTimeout'), null, null, false, true);
             $objTemplate->user = \Input::post('user');
         }
     }
     return $objTemplate->getResponse();
 }
All Usage Examples Of Contao\Input::post