php - Yii Framework - render form validation result in JSON format? -


I have a form that I want to display an error message. The correct message in a better UI like icons with animation.

While using the Yii framework, the error render is controlled by the classify class and I do not know how to modify the echo format even after reading the code.

I know that you can set a message in the rule () in the Model class, but it does not resonate if it passes the verification and I think that when you need a hard code , Then it is not a good idea to maintain it

  'message' = & gt; "{" Name ":" userName "," result ":" unsuccessful "," msg ":" taken from beforehand "}, ' 

Yes you can and here is an example my friend

  header ('content-type: application / jason'); $ ContactForm = New ContactForm (); $ ContactForm- & gt; Body = "some hunt"; $ ContactForm- & gt; Valid (); // boolean returns; right or wrong. If everything is okay then it becomes true other wrong eco json_encode ($ contactForm-> Errors);  

In your case something like this will

  $ myjsonValidationMessage = array (); $ ContactForm = New ContactForm (); If (! $ ContactForm- & gt; Validate ()) {$ myjsonValidationMessage ['message'] = $ contactForm- & gt; Errors; Echo json_encode ($ myjsonValidationMessage); }  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -