gint id;
ZakFormCgiForm *form;
+ ZakFormCgiFormElement *element;
ZakFormJsonProvider *provider;
"action", g_strdup_printf ("json_ini?filename=%s", filename),
NULL);
+ provider = zak_form_json_provider_new_from_file (filename);
+
if (zak_form_form_load_from_file (ZAK_FORM_FORM (form), XMLDIR "/cgi.xml"))
{
zak_form_cgi_form_set_bootstrap_version (form, "4");
if (zak_cgi_main_is_post (zakcgimain))
{
- /* validating the form */
zak_form_cgi_form_bind (form);
- if (zak_form_form_is_valid (ZAK_FORM_FORM (form)))
+
+ if (zak_cgi_main_get_stdin_field (zakcgimain, "delete") != NULL)
{
- g_string_append (str, "<div class=\"alert alert-success\" role=\"alert\">Form is valid!!!</div>");
- provider = zak_form_json_provider_new_from_file (filename);
if (provider != NULL)
{
- zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider));
+ zak_form_form_delete (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider));
g_object_unref (provider);
+ g_string_append (str, "<div class=\"alert alert-success\" role=\"alert\">Deleted!!!</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)
+ /* validating the form */
+ if (zak_form_form_is_valid (ZAK_FORM_FORM (form)))
+ {
+ g_string_append (str, "<div class=\"alert alert-success\" role=\"alert\">Form is valid!!!</div>");
+ if (provider != NULL)
+ {
+ zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider));
+ g_object_unref (provider);
+ }
+ }
+ else
{
- if (ar_messages->len > 0)
+ 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)
{
- g_string_append (str, "\n<ul>\n");
- for (m = 0; m < ar_messages->len; m++)
+ if (ar_messages->len > 0)
{
- g_string_append_printf (str, "\n<li>%s</li>", (gchar *)g_ptr_array_index (ar_messages, m));
+ 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, "\n</ul>\n");
}
- }
- g_string_append (str, "</div>");
+ g_string_append (str, "</div>");
+
+ element = zak_form_cgi_form_element_submit_new_attrs ("delete",
+ "zak-cgi-content", "Delete",
+ NULL);
+ zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
- g_string_append (str, zak_form_cgi_form_render (form));
+ g_string_append (str, zak_form_cgi_form_render (form));
+ }
}
}
else
{
+ element = zak_form_cgi_form_element_submit_new_attrs ("delete",
+ "zak-cgi-content", "Delete",
+ NULL);
+ zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
+
zak_form_form_clear (ZAK_FORM_FORM (form));
if (id > 0)
{
g_object_unref (provider);
}
}
+
g_string_append (str, zak_form_cgi_form_render (form));
}
}