validationyii2kartik-vactive-form

How to set errorPlacement after form-group in Yii2


How can I set errorPlacement in Yii2 activeform or using kartik active form just after form-group? Below are code for view file.

<div class="col-sm-6">
     <div class="form-group field-signupform-value1 required">
          <label class="control-label" for="signupform-value1">value1 Name</label>
          <input type="text" id="signupform-value1" class="form-control" name="SignupForm[value1]" placeholder="value1 Name" aria-required="true">
           <p class="help-block help-block-error"></p>
      </div> 
</div>

I want html code as below.

should auto add after .

<div class="col-sm-6">
     <div class="form-group field-signupform-value1 required">
          <label class="control-label" for="signupform-value1">value1 Name</label>
          <input type="text" id="signupform-value1" class="form-control" name="SignupForm[value1]" placeholder="value1 Name" aria-required="true"> 
      </div> 
    <p class="help-block help-block-error"></p> 
</div>

enter image description here


Solution

  • Looking at your inputs, it is not needed to change the replacement of the error message, though if you want to play with the input template properties, you can refer the following

    <?php $form = ActiveForm::begin([
              'fieldConfig'=>['template'=>'<div style="border:solid 1px black;padding-bottom:15px">{label}{input}{hint}</div>{error}']
    
    ]); ?>
    

    in the above template properties, you can change the placement of error template or event add some HTML inside it, hope it will help you.

    Edit: I have added inline css to div, you can put your css class which is applying outer border.