]> saetta.ns0.it Git - zakform/tests/commitdiff
Cgi: tested form validators (with messages).
authorAndrea Zagli <azagli@libero.it>
Sat, 14 May 2016 08:39:06 +0000 (10:39 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 14 May 2016 08:39:06 +0000 (10:39 +0200)
src/cgi_ini.c

index 8c04a940c1b5c22f7d9d591586f5756710cf7fe1..b0d35e24033b8c6c520611d4ef3f7b99376caaeb 100644 (file)
@@ -70,12 +70,30 @@ main (int argc, char *argv[])
                                        zak_cgi_form_bind (form);
                                        if (zak_form_form_is_valid (ZAK_FORM_FORM (form)))
                                                {
-                                                       g_string_append (str, "Form is valid!!!");
+                                                       g_string_append (str, "<div class=\"alert alert-success\" role=\"alert\">Form is valid!!!</div>");
                                                }
                                        else
                                                {
+                                                       g_string_append (str, "<div class=\"alert alert-danger\" role=\"alert\">Form is not valid!!!");
+
+                                                       guint m;
+                                                       GPtrArray *ar_messages = zak_form_form_get_messages (ZAK_FORM_FORM (form));
+                                                       if (ar_messages != NULL)
+                                                               {
+                                                                       if (ar_messages->len > 0)
+                                                                               {
+                                                                                       g_string_append (str, "\n<ul>\n");
+                                                                                       for (m = 0; m < ar_messages->len; m++)
+                                                                                               {
+                                                                                                       g_string_append_printf (str, "\n<li>%s</li>", (gchar *)g_ptr_array_index (ar_messages, m));
+                                                                                               }
+                                                                                       g_string_append (str, "\n</ul>\n");
+                                                                               }
+                                                               }
+
+                                                       g_string_append (str, "</div>");
+
                                                        g_string_append (str, zak_cgi_form_render (form));
-                                                       g_string_append (str, "Form is not valid!!!");
                                                }
                                }
                        else