Please, tell me, how to display only label and error for field by ActiveField in Yii2? I'm using Redactor and I want to display not only textarea, but also errors and label. Thanks.
The code example is given below.
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->errorSummary($model); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => 255]) ?>
<?php
echo yii\imperavi\Widget::widget(
[
'model' => $model,
'attribute' => 'text',
'options' => [],
]
);
?>
<br />
<div class="form-group">
<?= Html::submitButton(
$model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'),
['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']
) ?>
</div>
<?php ActiveForm::end(); ?>
Try this. I have given the option for saperate
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$form = \yii\widgets\ActiveForm::begin([
'id' => 'form-id',
'options' => ['class' => 'form-horizontal'],
'enableClientValidation'=> true,
'enableAjaxValidation'=> false,
'validateOnSubmit' => true,
'validateOnChange' => true,
'validateOnType' => true,
'action' => 'youractionurl',
'validationUrl' => 'yourvalidationurl'
]);
echo $form->field($model, 'fieldname')->begin();
echo Html::activeLabel($model,'fieldname'); //label
echo Html::activeTextInput($model, 'fieldname'); //Field
echo Html::error($model,'fieldname', ['class' => 'help-block']); //error
echo $form->field($model, 'fieldname')->end();
\yii\widgets\ActiveForm::end();
?>
<?php
$field = $form->field($model, 'username', ['options' => ['class' => 'form-group col-sm-6']]);
$field->template = "{label}\n{error}";
echo $field->textInput(['maxlength' => 255]);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With