public function create() { Assert::isTrue(IntelliForm::submitted(true), 'The form was not submitted.'); Assert::isTrue($this->checkFormValues() && $this->processForm(), 'The form data has not been processed correctly.'); // Back to homepage... $this->getRouter()->forward(DEFAULT_CONTROLLER, DEFAULT_ACTION); }
* - contain "$this" or "self", i.e. no direct reference to methods and properties of the calling controller! * - directly access to the context of the web application (variables $_GET, $_POST, $_SESSION, $GLOBALS, etc...), * because the calling controller is responsible for that! */ use PHPYAM\core\Core; ?> <h2>Form input</h2> <form id="form-id" name="form" method="post" action="<?php echo URL . 'form2/index'; ?> "> <fieldset style="margin-bottom: 6px;"> <?php echo \PHPYAM\libs\IntelliForm::seed(); ?> <legend>Please provide your name, email address (won't be published) and a comment</legend> <p> <label for="cname">Name (required, at least 2 characters)</label> <input id="cname" name="name" minlength="2" type="text" required /> </p> <p> <label for="cemail">E-Mail (required)</label> <input id="cemail" type="email" name="email" required /> </p> <p> <label for="curl">URL (optional)</label> <input id="curl" type="url"
/** * \PHPYAM\core\Router initialization */ private function initRouter() { // We set a session name based on the "baseurl" // to not mix the session data of different web applications // on a same webserver domain. session_name('SESS' . md5($_SERVER['HTTP_HOST'] . URL)); // Must be run asap by the router! if (session_id() === '') { session_start(); } // We set the language used for the PHPYAM messages. // Can be overridden later again, for example // in the object constructor of $this->authentication. putenv('LC_ALL=' . CLIENT_LANGUAGE); setlocale(LC_ALL, CLIENT_LANGUAGE); bindtextdomain('PHPYAM', __DIR__ . '/../locales'); bind_textdomain_codeset('PHPYAM', CLIENT_CHARSET); // Useful for Ajax requests (JQuery). header('Content-Type: text/html; charset=' . CLIENT_CHARSET); // The Ajax directive 'contentType: "application/x-www-form-urlencoded;charset=" . CLIENT_CHARSET' // is ignored by mostly every web browser (and should therefore not be used). // They will *always* send Ajax requests encoded with the UTF-8 charset. // We must therefore re-encode the received query data ($_POST, $_GET, ...) using the server&client charset: if (self::isAjaxCall() && is_array($GLOBALS['_' . $_SERVER['REQUEST_METHOD']])) { array_walk_recursive($GLOBALS['_' . $_SERVER['REQUEST_METHOD']], '\\PHPYAM\\libs\\StringUtils::stringEncode', array('from' => 'UTF-8', 'to' => CLIENT_CHARSET)); } // Prevent accidental submitting by refresh or back-button. // Use after session_start() and before any output to the browser (it uses header redirection). IntelliForm::antiRepost($_SERVER['REQUEST_URI']); // Clear expired form data. IntelliForm::purge(); // Create array with URL parts in $url. $this->splitUrl(); $this->loadResource(SYS_APP . '/security', SECURITY_POLICY); $authenticationClassName = SECURITY_POLICY; $this->authentication = new $authenticationClassName(); // We check that the header() statements have been taken into account, // which is only possible if the HTTP headers have not been sent yet. Assert::isFalse(headers_sent(), StringUtils::gettext('HTTP headers have already been sent.')); ob_start(); }