form_class
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
form_class [2019/10/22 20:02] – sahl | form_class [2021/03/11 19:44] (current) – [Easy forms] Adjusted file name sahl | ||
---|---|---|---|
Line 52: | Line 52: | ||
In order to provide an easier way to design forms, one can prepare a special html file | In order to provide an easier way to design forms, one can prepare a special html file | ||
- | <code html testform.frm> | + | <code html testform.form> |
< | < | ||
<text label=" | <text label=" | ||
Line 61: | Line 61: | ||
<code php> | <code php> | ||
- | $form = new Form(' | + | $form = new Form(' |
</ | </ | ||
Line 96: | Line 96: | ||
The validation function is passed the form, and should return true if everything is OK, otherwise it should trigger an error on the appropriate form field and return false. | The validation function is passed the form, and should return true if everything is OK, otherwise it should trigger an error on the appropriate form field and return false. | ||
+ | |||
+ | ===== Handling server side errors, when posting with javascript ===== | ||
+ | |||
+ | When doing a normal post, server side errors are automatic added to the form, but when posting using javascript, you need to pass server side errors back to the form. Platform provides easy functions to do that. | ||
+ | |||
+ | <code javascript frontend.js> | ||
+ | $.post(' | ||
+ | if (data.status == 1) { | ||
+ | // Everything is fine | ||
+ | } else { | ||
+ | // There was backend errors. Add them to the form. | ||
+ | add_errors_to_form(form, | ||
+ | } | ||
+ | }, ' | ||
+ | </ | ||
+ | |||
+ | <code php backend.php> | ||
+ | if ($form-> | ||
+ | else $result = array(' | ||
+ | echo json_encode($result); | ||
+ | </ |
form_class.1571774555.txt.gz · Last modified: 2019/10/22 20:02 by sahl