* @return array the validation rules. */ public function rules() { return [ [['first_name', 'last_name', 'email', 'subject', 'body'], 'required'], [['phone'], 'string'], ['email', 'email'], //['verifyCode', 'captcha'], [['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator2::className(), 'secret' => '6LdfZYMaAAAAAC7ob3M0WvCWKeY5fMSWi2Ny-ojy', // unnecessary if reСaptcha is already configured 'uncheckedMessage' => 'Please confirm that you are not a bot.'], ]; } /** * Sends an email to the specified email address using the information collected by this model. * @param string $email the target email address * @return boolean whether the model passes validation
* @return ArrayObject validators * @throws InvalidConfigException if any validation rule configuration is invalid */ public function createValidators() { $validators = new ArrayObject(); foreach ($this->rules() as $rule) { if ($rule instanceof Validator) { $validators->append($rule); } elseif (is_array($rule) && isset($rule[0], $rule[1])) { // attributes, validator type $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2)); $validators->append($validator); } else {
* * @return ArrayObject|\yii\validators\Validator[] all the validators declared in the model. */ public function getValidators() { if ($this->_validators === null) { $this->_validators = $this->createValidators(); } return $this->_validators; } /**
* * @return array a list of scenarios and the corresponding active attributes. */ public function scenarios() { $scenarios = [self::SCENARIO_DEFAULT => []]; foreach ($this->getValidators() as $validator) { foreach ($validator->on as $scenario) { $scenarios[$scenario] = []; } foreach ($validator->except as $scenario) { $scenarios[$scenario] = []; }
* Returns the attribute names that are subject to validation in the current scenario. * @return string[] safe attribute names */ public function activeAttributes() { $scenario = $this->getScenario(); $scenarios = $this->scenarios(); if (!isset($scenarios[$scenario])) { return []; } $attributes = array_keys(array_flip($scenarios[$scenario])); foreach ($attributes as $i => $attribute) { if ($attribute[0] === '!') {
* @param string $attribute the name of the attribute whose applicable validators should be returned. * If this is null, the validators for ALL attributes in the model will be returned. * @return \yii\validators\Validator[] the validators applicable to the current [[scenario]]. */ public function getActiveValidators($attribute = null) { $activeAttributes = $this->activeAttributes(); if ($attribute !== null && !in_array($attribute, $activeAttributes, true)) { return []; } $scenario = $this->getScenario(); $validators = []; foreach ($this->getValidators() as $validator) {
* * @param string $attribute attribute name * @return bool whether the attribute is required */ public function isAttributeRequired($attribute) { foreach ($this->getActiveValidators($attribute) as $validator) { if ($validator instanceof RequiredValidator && $validator->when === null) { return true; } } return false;
* @param $options array input options * @since 2.0.11 */ protected function addAriaAttributes(&$options) { if ($this->addAriaAttributes) { if (!isset($options['aria-required']) && $this->model->isAttributeRequired($this->attribute)) { $options['aria-required'] = 'true'; } if (!isset($options['aria-invalid']) && $this->model->hasErrors($this->attribute)) { $options['aria-invalid'] = 'true'; } }
$options = array_merge($this->inputOptions, $options); if ($this->form->validationStateOn === ActiveForm::VALIDATION_STATE_ON_INPUT) { $this->addErrorClassIfNeeded($options); } $this->addAriaAttributes($options); $this->adjustLabelFor($options); $this->parts['{input}'] = Html::activeTextInput($this->model, $this->attribute, $options); return $this; }
<div class="panel-heading"> <h3 class="panel-title">Send a Message</h3> </div> <div class="panel-body"> <div class="row"> <div class="col-md-4"> <?= $form->field($model, 'first_name')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'last_name') ?> <?= $form->field($model, 'email') ?> <?= $form->field($model, 'phone') ?> </div> <div class="col-xs-12 col-md-8"> <?= $form->field($model, 'subject') ?>
{ $_obInitialLevel_ = ob_get_level(); ob_start(); ob_implicit_flush(false); extract($_params_, EXTR_OVERWRITE); try { require $_file_; return ob_get_clean(); } catch (\Exception $e) { while (ob_get_level() > $_obInitialLevel_) { if (!@ob_end_clean()) { ob_clean(); }
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]); } /* @var $renderer ViewRenderer */ $renderer = $this->renderers[$ext]; $output = $renderer->render($this, $viewFile, $params); } else { $output = $this->renderPhpFile($viewFile, $params); } $this->afterRender($viewFile, $params, $output); } array_pop($this->_viewFiles); $this->context = $oldContext;
* @throws InvalidCallException if the view cannot be resolved. * @see renderFile() */ public function render($view, $params = [], $context = null) { $viewFile = $this->findViewFile($view, $context); return $this->renderFile($viewFile, $params, $context); } /** * Finds the view file based on the given view name. * @param string $view the view name or the [path alias](guide:concept-aliases) of the view file. Please refer to [[render()]] * on how to specify this parameter.
* These parameters will not be available in the layout. * @return string the rendering result. * @throws InvalidArgumentException if the view file or the layout file does not exist. */ public function render($view, $params = []) { $content = $this->getView()->render($view, $params, $this); return $this->renderContent($content); } /** * Renders a static string by applying a layout. * @param string $content the static string being rendered
} return $this->render('contact', [ 'website' => $this->website, 'model' => $model, 'connected' => $connected, 'agentConnected' => $agentConnected ]); } /** * @return string|Response */
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
$config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../config/web.php'), require(__DIR__ . '/../config/web-local.php') ); (new yii\web\Application($config))->run();
$_GET = [ 'slug' => 'chris', ]; $_SESSION = [ '__flash' => [], ];