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(); }
/** * @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; }
/** * @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(); }
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(); }
public function run() { $formId = $this->formOptions['id']; $this->getView()->registerCss("#{$formId} button {-webkit-box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.2);box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.2);}"); $form = ActiveForm::begin(array_merge($this->defaultFormOptions, $this->formOptions)); print Html::beginTag('div', ['class' => 'row']); print Html::beginTag('div', ['class' => 'col-xs-12']); print Html::beginTag('div', ['class' => 'input-group']); if ($this->inputWidget) { print $form->field($this->model, $this->attribute, ['template' => '{input}'])->widget($this->inputWidget, $this->inputOptions); } else { print $form->field($this->model, $this->attribute, ['template' => '{input}'])->input($this->inputType, array_merge(['placeholder' => $this->model->getAttributeLabel($this->attribute), 'class' => 'form-control'], $this->inputOptions)); } print Html::beginTag('span', ['class' => 'input-group-btn']); print Html::submitButton(Yii::t('hipanel', 'Search'), ['class' => 'btn btn-flat ' . $this->buttonColor]); print Html::endTag('span'); print Html::endTag('div'); print Html::endTag('div'); print Html::endTag('div'); ActiveForm::end(); }
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?> <?php echo $form->field($model, 'name'); ?> <?php echo $form->field($model, 'email'); ?> <?php echo $form->field($model, 'subject'); ?> <?php echo $form->field($model, 'body')->textArea(['rows' => 6]); ?> <?php echo $form->field($model, 'verifyCode')->widget(Captcha::className(), ['template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>']); ?> <div class="form-group"> <?php echo Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']); ?> </div> <?php ActiveForm::end(); ?> </div> </div> </div>
$this->title = Yii::t('app', 'Добавление части'); $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Услуга: ' . $model->service->title . ' / ' . $model->lang), 'url' => ['services/update', 'id' => $model->serviceId]]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="services-parts-record-create"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php $form = \yii\bootstrap\ActiveForm::begin(['enableClientValidation' => false]); ?> <?php echo \app\modules\core\widgets\LanguageTabs::widget(['models' => $models, 'form' => $form, 'view' => $this, 'template' => '_form']); ?> <div class="form-group"> <?php echo Html::submitButton('Добавить', ['class' => 'btn btn-success']); ?> </div> <?php \yii\bootstrap\ActiveForm::end(); ?> </div>
<div class="site-login"> <h1><?= Html::encode($this->title) ?></h1> <p>Для авторизации заполните следующий поля:</p> <?php $form = ActiveForm::begin([ 'id' => 'login-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'username') ?> <?= $form->field($model, 'password')->passwordInput() ?> <?= $form->field($model, 'rememberMe')->checkbox([ 'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>", ]) ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Вход', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> </div> <?php ActiveForm::end(); ?> </div>
$toolbar = Yii::$app->toolbar; ?> <?php $form = ActiveForm::begin(); ?> <?php $toolbar->save()->saveStay()->back(); if (!$model->getIsNewRecord()) { $url = Yii::$app->getUrlManager()->createUrlFrontend(Route::category($model)); $toolbar->addButton(Html::a($toolbar->createText('eye', Yii::t('cms', 'Go to category')), $url, $toolbar->createButtonOptions(['target' => '_blank']))); } ?> <h1><?php echo $title; ?> </h1> <div class="row"> <div class="col-md-12"> <?php echo Tabs::widget(['items' => [['label' => Yii::t('cms', 'Category'), 'content' => $this->render('_tab_category', ['form' => $form, 'model' => $model, 'parents' => $parents, 'templates' => $templates])], ['label' => Yii::t('cms', 'Publishing'), 'content' => $this->render('_tab_publishing', ['form' => $form, 'model' => $model])], ['label' => Yii::t('cms', 'Images'), 'content' => $this->render('_tab_images', ['form' => $form, 'model' => $model])], ['label' => Yii::t('cms', 'Seo'), 'content' => $this->render('_tab_seo', ['form' => $form, 'model' => $model])], ['label' => Yii::t('cms', 'Info'), 'content' => $this->render('_tab_info', ['form' => $form, 'model' => $model])]]]); ?> </div> </div> <?php $form = ActiveForm::end();
private function buildForm($action = 'update') { // Build form for type. $this->model = new CrelishDynamicJsonModel([], ['ctype' => $this->ctype, 'uuid' => $this->uuid]); // Save content if post request. if (!empty(\Yii::$app->request->post()) && !\Yii::$app->request->isAjax) { $oldData = []; // Load old data. if (!empty($this->model->uuid)) { $oldData = Json::decode(file_get_contents(\Yii::getAlias('@app/workspace/data/') . DIRECTORY_SEPARATOR . $this->ctype . DIRECTORY_SEPARATOR . $this->model->uuid . '.json')); } $this->model->attributes = $_POST['CrelishDynamicJsonModel'] + $oldData; if ($this->model->validate()) { $this->model->save(); \Yii::$app->session->setFlash('success', 'Content saved successfully...'); header('Location: ' . Url::to(['content/update', 'ctype' => $this->ctype, 'uuid' => $this->model->uuid])); exit(0); } else { $errors = $this->model->errors; } } ob_start(); $form = ActiveForm::begin(['id' => 'content-form']); // Start output. echo '<div class="gc-bc--palette-clouds gc-bs--soft gc-ptb--2">'; // Display messages. foreach (\Yii::$app->session->getAllFlashes() as $key => $message) { echo '<div class="c-alerts__alert c-alerts__alert--' . $key . '">' . $message . '</div>'; } echo Html::beginTag("div", ['class' => 'o-grid']); // TODO: This has to be dynamicaly handled like it's done in frontend. // Also the tabs and grouping mechanics have to be implemented. // Get the tabs (there has to be at least one). $tabs = $this->model->fieldDefinitions->tabs; //var_dump($tabs); foreach ($tabs as $tab) { // Loop through tabs. foreach ($tab->groups as $group) { // Loop through groups. $widthClass = !empty($group->settings->width) ? 'o-grid__cell--width-' . $group->settings->width : ''; echo Html::beginTag('div', ['class' => 'o-grid__cell ' . $widthClass]); echo Html::beginTag('div', ['class' => 'c-card']); echo Html::tag('div', $group->label, ['class' => 'c-card__item c-card__item--divider']); echo Html::beginTag('div', ['class' => 'c-card__item']); foreach ($this->model->fieldDefinitions->fields as $field) { if (!in_array($field->key, $group->fields)) { continue; } // Build form fields. $fieldOptions = !empty($field->options) ? $field->options : []; if (strpos($field->type, 'widget_') !== false) { $widget = str_replace('widget_', '', $field->type); echo $form->field($this->model, $field->key)->widget($widget::className())->label($field->label); } elseif ($field->type == 'dropDownList') { echo $form->field($this->model, $field->key)->{$field->type}((array) $field->items, (array) $fieldOptions)->label($field->label); } elseif ($field->type == 'matrixConnector') { echo plugins\matrixconnector\MatrixConnector::widget(['formKey' => $field->key, 'data' => $this->model[$field->key]]); } elseif ($field->type == 'assetConnector') { echo plugins\assetconnector\AssetConnector::widget(['formKey' => $field->key, 'data' => $this->model[$field->key]]); } elseif ($field->type == 'dataList') { echo DataList::widget(['formKey' => $field->key, 'data' => $this->model[$field->key]]); } else { echo $form->field($this->model, $field->key)->{$field->type}((array) $fieldOptions)->label($field->label); } } echo Html::endTag('div'); echo Html::endTag('div'); echo Html::endTag('div'); } } echo Html::endTag('div'); echo '</div>'; ActiveForm::end(); return ob_get_clean(); }
protected function buildForm($action = 'update', $settings = array()) { //default settings $defaults = array('id' => 'content-form', 'outerClass' => 'gc-bc--palette-clouds gc-bs--soft gc-ptb--2', 'groupClass' => 'c-card', 'tabs' => []); $settings = $settings + $defaults; // Build form for type. $this->model = new CrelishDynamicJsonModel([], ['ctype' => $this->ctype, 'uuid' => $this->uuid]); // Save content if post request. if (in_array($action, array('update', 'create')) && !empty(\Yii::$app->request->post()) && !\Yii::$app->request->isAjax) { $oldData = []; // Load old data. if (!empty($this->model->uuid)) { $oldData = Json::decode(file_get_contents(\Yii::getAlias('@app/workspace/data/') . DIRECTORY_SEPARATOR . $this->ctype . DIRECTORY_SEPARATOR . $this->model->uuid . '.json')); } $attributes = $_POST['CrelishDynamicJsonModel'] + $oldData; foreach ($attributes as $key => $val) { foreach ($this->model->fieldDefinitions->fields as $field) { if ($field->key == $key) { if (isset($field->transform)) { if (!isset($oldData[$key]) || $oldData[$key] != $attributes[$key]) { //we need to transform! $transformer = 'giantbits\\crelish\\components\\transformer\\CrelishFieldTransformer' . ucfirst(strtolower($field->transform)); $transformer::transform($attributes[$key]); } } break; } } } $this->model->attributes = $attributes; if ($this->model->validate()) { $this->model->save(); \Yii::$app->session->setFlash('success', 'Content saved successfully...'); header('Location: ' . Url::to(['content/update', 'ctype' => $this->ctype, 'uuid' => $this->model->uuid])); exit(0); } else { $errors = $this->model->errors; } } ob_start(); $form = ActiveForm::begin(['id' => $settings['id']]); // Start output. echo Html::beginTag("div", ['class' => $settings['outerClass']]); // Display messages. foreach (\Yii::$app->session->getAllFlashes() as $key => $message) { //echo '<div class="c-alerts__alert c-alerts__alert--'.$key.'">'.$message.'</div>'; } echo Html::beginTag("div", ['class' => 'o-grid']); // TODO: This has to be dynamicaly handled like it's done in frontend. // Also the tabs and grouping mechanics have to be implemented. // Get the tabs (there has to be at least one). $tabs = $this->model->fieldDefinitions->tabs; //var_dump($tabs); foreach ($tabs as $tab) { // Loop through tabs. //check tab overrides if (isset($settings['tabs'][$tab->key])) { foreach ($settings['tabs'][$tab->key] as $key => $val) { $tab->{$key} = $val; } } if (isset($tab->visible) && $tab->visible === false) { continue; } foreach ($tab->groups as $group) { // Loop through groups. $widthClass = !empty($group->settings->width) ? 'o-grid__cell--width-' . $group->settings->width : ''; $groupSettings = property_exists($group, 'settings') ? $group->settings : null; echo Html::beginTag('div', ['class' => 'o-grid__cell ' . $widthClass]); echo Html::beginTag('div', ['class' => $settings['groupClass']]); if (!empty($groupSettings) && property_exists($groupSettings, 'showLabel') && $group->settings->showLabel !== false) { echo Html::tag('div', $group->label, ['class' => 'c-card__item c-card__item--divider']); } echo Html::beginTag('div', ['class' => 'c-card__item']); foreach ($this->model->fieldDefinitions->fields as $field) { if (!in_array($field->key, $group->fields)) { continue; } // Build form fields. $fieldOptions = !empty($field->options) ? $field->options : []; if (strpos($field->type, 'widget_') !== false) { $widget = str_replace('widget_', '', $field->type); echo $form->field($this->model, $field->key)->widget($widget::className())->label($field->label); } elseif ($field->type == 'dropDownList') { echo $form->field($this->model, $field->key)->{$field->type}((array) $field->items, (array) $fieldOptions)->label($field->label); } elseif ($field->type == 'submitButton') { echo Html::submitButton($field->label, array('class' => 'c-button c-button--brand c-button--block')); } else { $class = 'giantbits\\crelish\\plugins\\' . strtolower($field->type) . '\\' . ucfirst($field->type); // Check for crelish special fields. if (class_exists($class)) { echo $class::widget(['formKey' => $field->key, 'data' => $this->model[$field->key], 'field' => $field]); } else { echo $form->field($this->model, $field->key)->{$field->type}((array) $fieldOptions)->label($field->label); } } } echo Html::endTag('div'); echo Html::endTag('div'); echo Html::endTag('div'); } } echo Html::endTag('div'); echo Html::endTag('div'); ActiveForm::end(); return ob_get_clean(); }
</div> --> </section> <section> <label class="checkbox"> <input id="rememberMe" type="checkbox" name="LoginForm[rememberMe]"> <i></i>Recordarme</label> </section> </fieldset> <footer> <button type="submit" class="btn btn-primary"> Entrar </button> </footer> <?php $form = ActiveForm::end(); ?> </div> </div> </div> </div> </div> </div> <script type="text/javascript"> $(function() { $('#rememberMe').on('change', function(e) { e.stopPropagation(); this.value = this.checked ? 1 : 0; });
<?php use yii\bootstrap\ActiveForm as BootForm; use yii\bootstrap\Html as BootHtml; $form = BootForm::begin(); echo $form->field($model, 'email'); echo $form->field($model, 'password')->passwordInput(); echo BootHtml::submitButton('Войти', ['class' => 'btn btn-default']); BootForm::end();
/** * Prepares the caching section * * @return array the configuration of the section */ protected function sectionCaching() { $ret = []; foreach (Yii::$app->components as $id => $component) { $instance = Yii::$app->{$id}; if (!$instance instanceof Cache) { continue; } $title = $this->valueCode($id); ob_start(); ActiveForm::begin(); echo $this->valueCode($instance->className()); echo $this->valueModal('Cache ' . $id, $this->valueVarDump($instance), 'Show config'); echo Html::hiddenInput('flush-cache', $id); echo Html::submitButton('Flush', ['class' => 'btn btn-xs btn-danger', 'data' => ['confirm' => 'Are you sure?']]); ActiveForm::end(); $ret[$title] = ob_get_clean(); } return $ret; }
public function api_form($options = []) { if (is_array($options) && count($options)) { $this->options = array_merge($this->options, $options); } $model = new Subscriber(); ob_start(); $form = ActiveForm::begin(['enableAjaxValidation' => true, 'action' => Url::to(['/admin/subscribe/send']), 'layout' => 'inline']); switch (Yii::$app->session->getFlash(Subscriber::FLASH_KEY)) { case 'success': Yii::$app->getView()->registerJs('alert("' . Yii::t('easyii/subscribe/api', 'You have successfully subscribed') . '");'); break; case 'error': Yii::$app->getView()->registerJs('alert("' . Yii::t('easyii/subscribe/api', 'An error has occurred') . '");'); break; } echo $form->field($model, 'email')->input('email', ['placeholder' => 'E-mail']); echo Html::submitButton(Yii::t('easyii/subscribe/api', $this->options['buttonText']), ['class' => $this->options['buttonClass'], 'id' => 'subscriber-send']); ActiveForm::end(); return ob_get_clean(); }