Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show multiple validate message to each field following ActiveForm::validate() #45

Closed
yoyhosoft opened this issue Mar 20, 2015 · 1 comment
Labels

Comments

@yoyhosoft
Copy link

I have question
I use this code
Address
'; $editable = Editable::begin([ 'model'=>$model, 'attribute'=>'address', 'size'=>'md', 'displayValue' => '15th Main, OK, 10322', 'options'=>['placeholder'=>'Enter address...'] ]); $form = $editable->getForm(); echo Html::hiddenInput('kv-complex', '1'); $editable->afterInput = $form->field($model, 'province_id')->widget(\kartik\widgets\Select2::classname(), [ 'data'=>ArrayHelper::map($modelProvince, 'province_id', 'province_name'), 'options'=>['placeholder'=>'Enter province...'], 'pluginOptions'=>['allowClear'=>true] ]) . "\n" . $form->field($model, 'zipcode')->textInput(['placeholder'=>'Enter zip code...']); Editable::end(); ?>

When I submit data, in Controller I validate data by use below function.
ActiveForm::validate($model)

and return validated data as below
{"usershop-address":["Address cannot be blank."],"usershop-province_id":["Province cannot be blank."],"usershop-zipcode":["Zipcode cannot be blank."]}

Question is, How to show each error message to each input field?

Thanks,

@kartik-v
Copy link
Owner

You should use ideally yii model validation rules for each attribute for the above... and not use Controller to validate this. Read about yii model validation rules in yii guides where you can set required property for each attribute to achieve what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants