public function run() { parent::run(); $model = new \app\models\ProjectSimpleForm(); $form = ActiveForm::begin(['id' => 'project-simple-form', 'action' => ['/project/simplecreate'], 'layout' => 'inline', 'validateOnChange' => false, 'validateOnBlur' => false]); echo $form->field($model, 'title')->textInput(['maxlength' => 255, 'class' => 'form-control input-sm'])->label(false); echo '<div class="form-group">' . Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-sm btn-success', 'style' => 'margin: 5px 5px 5px 0;']) . Html::resetButton(Yii::t('app', 'Cancel'), ['class' => 'btn btn-xs', 'style' => 'margin: 5px;']) . '</div>'; ActiveForm::end(); $this->registerJs(); }
public function run() { $this->options['class'] = 'ajax-form'; parent::run(); $content = ob_get_clean(); return Html::tag('div', $content, ['class' => 'ajax-form-wrapper', 'style' => "max-width:{$this->maxWidth}px"]); }
/** * @param array $config * @return string */ public static function generate($config = []) { $reservedAttributeNames = ['plainHTML']; ob_start(); $form = ActiveForm::begin($config['formConfig']); foreach ($config['fields'] as $attribute => $fieldConfig) { if (in_array($attribute, $reservedAttributeNames)) { echo $fieldConfig; } else { if (isset($fieldConfig['render'])) { $render = $fieldConfig['render']; switch ($render['type']) { case 'inline': $method = $render['method']; $options = isset($render['options']) ? $render['options'] : []; echo $form->field($fieldConfig['model'], $attribute, isset($fieldConfig['options']) ? $fieldConfig['options'] : [])->{$method}($options); break; case 'widget': $class = $render['class']; $options = isset($render['options']) ? $render['options'] : []; echo $form->field($fieldConfig['model'], $attribute, isset($fieldConfig['options']) ? $fieldConfig['options'] : [])->widget($class, $options); break; } } else { echo $form->field($fieldConfig['model'], $attribute, isset($fieldConfig['options']) ? $fieldConfig['options'] : []); } } } ActiveForm::end(); $result = ob_get_contents(); ob_end_clean(); return $result; }
/** * Scan directory with templates and show them in dropdown list * * @param \yii\bootstrap\ActiveForm $form * * @return string */ public function layoutSelector($form) { $items = []; $pathToTemplates = Yii::getAlias('@app/templates/'); Yii::$app->assetManager->publish($pathToTemplates); $assetUrl = Yii::$app->assetManager->getPublishedUrl($pathToTemplates); $layoutFolders = scandir($pathToTemplates); foreach ($layoutFolders as $layoutFolder) { if (!in_array($layoutFolder, ['.', '..']) && is_dir($pathToTemplates . $layoutFolder)) { $items[$layoutFolder] = Html::img($assetUrl . '/' . $layoutFolder . '/backend_image.png'); } } return $form->field($this, 'layout')->radioList($items); }
/** * регистрация юзера по имейл * если регистрация для покупки, то передаются параметры рекомендатель и урл * @param type $affiliate_id * @param type $url_id * @return type * @throws \yii\web\NotFoundHttpException */ public function actionUser($affiliate_id = null, $url_id = null) { $request = Yii::$app->request; $model = new \app\models\registration\UserForm(); if ($request->isAjax && $model->load($request->post())) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load($request->post()) && $model->validate()) { $user = User::findByUsername($model->email); if (!$user) { $user = $model->save(); } $user->setCookie(); if ($affiliate_id === null || $url_id === null) { Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту'); return $this->goHome(); } $url = Url::findOne($url_id); if (!$url) { throw new \yii\web\NotFoundHttpException('Урл не найден'); } $user->purchase($affiliate_id, $url); return $this->redirect($url->link); } return $this->render('user', ['model' => $model]); }
public function field($model, $attribute, $options = []) { if (!isset($options['labelOptions']['label'])) { $options['labelOptions']['label'] = Html::encode($model->getAttributeLabel($attribute)) . ':'; } return parent::field($model, $attribute, $options); }
public function init() { $this->fieldConfig = ['template' => "<div class=\"row\">\n <div class=\"col-xs-6\">{label}</div>\n <div class=\"col-xs-6\"> <span class=\"tooltip-field pull-right\"> {hint} </span> <span class=\"tooltip-error-field pull-right\"> {error} </span> </div>\n \n<div class=\"col-xs-12\">{input}</div>\n </div>"]; $this->fieldClass = ActiveField::className(); echo Html::tag('span', AmosIcons::show('alert'), ['id' => 'errore-alert-common', 'class' => 'errore-alert bk-noDisplay', 'title' => \Yii::t('app', 'La tab contiene degli errori')]); parent::init(); }
public function saveData() { if ($this->model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; // perform AJAX validation echo ActiveForm::validate($this->model); Yii::$app->end(); return ''; } /** @var User|bool $registeredUser */ $registeredUser = $this->model->register(); if ($registeredUser !== false) { $module = UsersModule::module(); // login registered user if there's no need in confirmation $shouldLogin = $module->allowLoginInactiveAccounts || $module->emailConfirmationNeeded === false; if ($module->emailConfirmationNeeded === true && $registeredUser->is_active) { $shouldLogin = true; } if ($shouldLogin && $registeredUser->login(UsersModule::module()->loginDuration)) { $returnUrl = Yii::$app->request->get('returnUrl'); if ($returnUrl !== null) { return $this->controller->redirect($returnUrl); } } return $this->controller->goBack(); } } return ''; }
/** * @inheritdoc */ public function init() { if ($this->pjax) { $this->options['data-pjax'] = 1; } parent::init(); }
public function actionUser() { //make a db con or go back $db = new InstallConfig(); try { $db->con(); } catch (\yii\db\Exception $e) { return $this->render('config', array('model' => $db, "error" => "No DB")); } if (!User::find()->All() == null) { return $this->redirect('?r=install/finish'); //Yii::$app->end(); } //user $model = new User(); $model->scenario = 'create'; $model->language = 'he_il'; $model->timezone = 'Asia/Jerusalem'; if ($model->load(Yii::$app->request->post())) { //$model->save(); if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return \yii\bootstrap\ActiveForm::validate($model); } if ($model->save()) { $this->redirect('?r=install/finish'); } } return $this->render('user', array('model' => $model)); }
public function init() { $this->initForm(); if (empty($this->fieldConfig['options']) && $this->floatingLabel && $this->layout !== 'horizontal') { $this->fieldConfig['options'] = ['class' => 'form-group floating-label']; } parent::init(); }
public function actionValidateOptionsForm() { $cOptFrm = new OptionsForm(); if (Yii::$app->request->isAjax && $cOptFrm->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($cOptFrm); } }
public function run() { echo Html::endTag('div'); $buttons = Html::tag('div', Html::submitButton(__('Search'), ['class' => 'btn btn-primary'])); echo Html::tag('div', $buttons, ['class' => 'panel-footer ' . $this->extraClass . $this->targetClass]); echo Html::endTag('div'); parent::run(); }
public function run() { ob_start(); ob_implicit_flush(false); parent::run(); ob_end_clean(); echo Html::endTag('div'); }
/** * @inheritdoc */ public function run() { $form = ActiveForm::begin(); echo $form->errorSummary($this->commentModel); echo $form->field($this->commentModel, 'title')->textInput(['maxlength' => true]); echo $form->field($this->commentModel, 'content')->textarea($this->textAreaOptions); echo Html::submitButton(empty($this->buttonLabel) ? Yii::t('app', 'Save') : $this->buttonLabel, $this->buttonOptions); ActiveForm::end(); }
/** * @inheritdoc */ public function field($model, $attribute, $options = []) { if (!array_key_exists('class', $options)) { $type = null; if (array_key_exists('type', $options)) { $type = $options['type']; unset($options['type']); } else { // schema if ($model instanceof ActiveRecord) { $columnSchema = $model::getTableSchema()->getColumn($attribute); if ($columnSchema) { $type = $columnSchema->type; if (in_array($columnSchema->type, [Schema::TYPE_PK, Schema::TYPE_BIGPK, Schema::TYPE_SMALLINT, Schema::TYPE_INTEGER, Schema::TYPE_BIGINT])) { if ($columnSchema->size == 1 && $columnSchema->unsigned) { $type = Schema::TYPE_BOOLEAN; } else { $options = array_merge($options, ['size' => $columnSchema->size, 'unsigned' => $columnSchema->unsigned]); } } elseif ($columnSchema->type == Schema::TYPE_STRING) { $options['size'] = $columnSchema->size; } elseif (in_array($columnSchema->type, [Schema::TYPE_DECIMAL, Schema::TYPE_MONEY])) { $options = array_merge($options, ['size' => $columnSchema->size, 'scale' => $columnSchema->scale, 'unsigned' => $columnSchema->unsigned]); } } } // rules foreach ($model->rules() as $rule) { if (is_array($rule[0]) && in_array($attribute, $rule[0]) || $rule[0] == $attribute) { if (in_array($rule[1], ['email', 'url'])) { $type = $rule[1]; } elseif ($rule[1] == 'string') { if (is_null($type)) { $type = $rule[1]; } if (array_key_exists('max', $rule)) { $options['size'] = $rule['max']; } if (array_key_exists('length', $rule)) { if (is_array($rule['length'])) { if (count($rule['length']) == 2) { $options['size'] = $rule['length'][1]; } } else { $options['size'] = $rule['length']; } } } } } } if (!is_null($type)) { $options['class'] = 'yii\\mozayka\\form\\fields\\' . ucfirst($type) . 'Field'; } } return parent::field($model, $attribute, $options); }
public function run() { $request = Yii::$app->getRequest(); $this->modelComment = new BlogComment(); if ($request->isAjax && $this->modelComment->load($request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; $errors = ActiveForm::validate($this->modelComment); echo json_encode($errors); } }
public function init() { $this->fieldConfig['horizontalCssClasses']['label'] = 'col-sm-' . $this->labelCols; $this->fieldConfig['horizontalCssClasses']['wrapper'] = 'col-sm-' . (self::COLS_TOTAL - $this->labelCols); parent::init(); $params = Yii::$app->request->queryParams; if (!empty($params['_return_url'])) { echo Html::hiddenInput('_return_url', $params['_return_url']); } }
public function run() { parent::run(); if (isset(Html::$inputIdPrefix)) { Html::$inputIdPrefix = ''; } if (isset(Html::$inputIdSuffix)) { Html::$inputIdSuffix = ''; } }
/** * @inheritdoc */ public function init() { parent::init(); // $id = $this->options['id']; $clientSideKey = Yii::$app->get('braintree')->clientSideKey; $view = $this->getView(); BraintreeAsset::register($view); // $view->registerJs("braintree.setup('$clientSideKey', 'custom', {id: '$id'});"); $view->registerJs("braintreeClient = new braintree.api.Client({clientToken: '{$clientSideKey}'});"); $this->fieldClass = ActiveField::className(); }
public function api_form($options = []) { $model = new Subscriber(); $options = array_merge($this->_defaultFormOptions, $options); ob_start(); $form = ActiveForm::begin(['enableAjaxValidation' => true, 'action' => Url::to(['/admin/subscribe/send']), 'layout' => 'inline']); echo Html::hiddenInput('errorUrl', $options['errorUrl'] ? $options['errorUrl'] : Url::current([self::SENT_VAR => 0])); echo Html::hiddenInput('successUrl', $options['successUrl'] ? $options['successUrl'] : Url::current([self::SENT_VAR => 1])); echo $form->field($model, 'email')->input('email', ['placeholder' => 'E-mail']); echo Html::submitButton(Yii::t('easyii/subscribe/api', 'Subscribe'), ['class' => 'btn btn-primary', 'id' => 'subscriber-send']); ActiveForm::end(); return ob_get_clean(); }
/** * Adds some default configuration. I.e. form name and layout class. * @inheritdoc */ public function init() { if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) { throw new InvalidConfigException('Invalid layout type: ' . $this->layout); } if ($this->layout !== 'default') { Html::addCssClass($this->options, 'form-' . $this->layout); } if ($this->name) { $this->options['name'] = $this->name; } parent::init(); }
public function actionInfo($id = '') { $model = new MenuForm(); if (Yii::$app->request->isAjax && \Yii::$app->request->post('ajax', '') == 'info-form' && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { $model->save(); Yii::$app->end(); } $model->update($id); return $this->render('info', ['model' => $model]); }
public function actionRegister() { $model = new SignupForm(); $model->scenario = 'short_register'; if (\Yii::$app->request->isAjax && \Yii::$app->request->isPost) { \Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(\Yii::$app->request->post()) && $model->signup()) { print_r($model->getAttributes()); die; } return $this->render("register", ['model' => $model]); }
public function actionPassword_change() { $model = new \app\models\Form\PasswordNew(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->action(\Yii::$app->user->identity)) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } else { return $this->render(['model' => $model]); } }
public function run() { Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../')); $model = new ExampleModel(); $request = Yii::$app->getRequest(); if ($request->isPost && $request->post('ajax') !== null) { $model->load(Yii::$app->request->post()); Yii::$app->response->format = Response::FORMAT_JSON; $result = ActiveForm::validate($model); return $result; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { } return $this->controller->render('@unclead-examples/views/example.php', ['model' => $model]); }
public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } return $this->render('login_form', ['model' => $model]); }
public function field($model, $attribute, $options = []) { $fields = []; $isMultilingualOption = isset($options['multilingual']) && $options['multilingual']; $isMultilingualAttribute = method_exists($model, 'isMultilingual') && $model->isMultilingual() && $model->hasLangAttribute($attribute); if ($isMultilingualOption || $isMultilingualAttribute) { $languages = array_keys(Yii::$app->yee->languages); foreach ($languages as $language) { $fields[] = parent::field($model, $attribute, array_merge($options, ['language' => $language])); } } else { return parent::field($model, $attribute, $options); } return new MultilingualFieldContainer(['fields' => $fields]); }
public function actionRegister() { $model = new SignupForm(); //$model->scenario = 'short_register'; if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } } if ($model->load(Yii::$app->request->post()) && $model->signup()) { Yii::$app->session->setFlash('success', 'Success register'); } return $this->render('register', ['model' => $model]); }
public function actionContact() { $this->layout = 'inner'; $model = new ContactForm(); if (Yii::$app->request->isAjax && $model->load(\Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->validate()) { $body = " <div>Body: <b> " . $model->body . " </b></div>"; $body .= " <div>Email: <b> " . $model->email . " </b></div>"; Yii::$app->common->sendMail($model->subject, $body); print 'Send success'; die; } return $this->render('contact', ['model' => $model]); }