简体   繁体   中英

How can I save data in form fields if validation don't pass?

I have a complex form (CActiveForm) consists of 4 questions with several checkbox lists and radio buttons. When user visits the page, only the first question is visible. The each next question will appear only if at least one checkbox was checked in previous question (jquery).

Now if I submit form, but its validation fails, error messages display above the form, all checkboxes became unchecked and all question except the first one became invisible.

Is there a simple way to save checked checkboxes and display all questions if form's validation fails?

Maybe yii1 have some standard methods for this? Or the only solution is using of Ajax validation?

我建议您使用类似依赖性下拉列表的问题, 请在此处显示,或者是否使用yii2, 请参见此处

You could use some local storage, either via a SESSION variable in something like PHP or indexDB in Javascript to store the form values each time on submit, before validation. Then if validation fails, refill in the form with the saved form data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM