本文整理汇总了PHP中yii\bootstrap\ActiveForm类的典型用法代码示例。如果您正苦于以下问题:PHP ActiveForm类的具体用法?PHP ActiveForm怎么用?PHP ActiveForm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActiveForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* @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;
}
示例2: layoutSelector
/**
* 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);
}
示例3: actionUser
/**
* регистрация юзера по имейл
* если регистрация для покупки, то передаются параметры рекомендатель и урл
* @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]);
}
示例4: actionUser
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));
}
示例5: saveData
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 '';
}
示例6: actionValidateOptionsForm
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);
}
}
示例7: run
/**
* @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();
}
示例8: run
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);
}
}
示例9: run
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();
}
示例10: run
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"]);
}
示例11: field
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);
}
示例12: init
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();
}
示例13: init
/**
* @inheritdoc
*/
public function init()
{
if ($this->pjax) {
$this->options['data-pjax'] = 1;
}
parent::init();
}
示例14: run
public function run()
{
ob_start();
ob_implicit_flush(false);
parent::run();
ob_end_clean();
echo Html::endTag('div');
}
示例15: run
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();
}