]> saetta.ns0.it Git - libzakcgi/commitdiff
Started of loading ZakFormForm from xml file.
authorAndrea Zagli <azagli@libero.it>
Thu, 5 Nov 2015 19:38:05 +0000 (20:38 +0100)
committerAndrea Zagli <azagli@libero.it>
Thu, 5 Nov 2015 19:38:05 +0000 (20:38 +0100)
25 files changed:
.gitignore
src/Makefile.am
src/formelementcheck.c
src/formelementcheck.h
src/formelementhidden.c
src/formelementhidden.h
src/formelementpassword.c
src/formelementpassword.h
src/formelementselect.c
src/formelementselect.h
src/formelementstring.c
src/formelementstring.h
src/formelementsubmit.c
src/formelementsubmit.h
src/formelementtext.c
src/formelementtext.h
src/formelementtextarea.c
src/formelementtextarea.h
src/main.c
src/main.h
tests/Makefile.am
tests/form.c
tests/form_xml.c [new file with mode: 0644]
tests/form_xml.xml [new file with mode: 0644]
tests/querystring.c

index 6affd6dc69c98c17885c9ecb700f2188e85d2fa8..6e5655f8fc0988ca4ff8c932232ea6ce342f715d 100644 (file)
@@ -53,6 +53,7 @@ Rules-quot
 tests/cookies
 tests/env
 tests/form
+tests/form_xml
 tests/querystring
 tests/redirect
 tests/session
index 62477160ab78d3ab3893a235f366fa9e4134c2bf..9a27f2d24d03cc97e0d79a2805d49d2f722d8f91 100644 (file)
@@ -1,3 +1,13 @@
+if PLATFORM_WIN32
+libmodulesext = -0.dll
+libmodulesdir = $(bindir)
+else
+libmodulesext = .so
+libmodulesdir = $(libdir)
+endif
+
+libzakformmodulesdir = `pkg-config --variable=modulesdir libzakform`
+
 LIBS = $(ZAKCGI_LIBS)
 
 AM_CPPFLAGS = $(ZAKCGI_CFLAGS) \
@@ -42,3 +52,10 @@ libzakcgi_include_HEADERS = \
                             url.h
 
 libzakcgi_includedir = $(includedir)/libzakcgi
+
+install-exec-hook:
+       cd $(libzakformmodulesdir) && \
+       ln -s -f $(libmodulesdir)/libzakcgi$(libmodulesext) .
+
+uninstall-hook:
+       rm -f $(libzakformmodulesdir)/libzakcgi$(libmodulesext)
index 21fd3da760cb7b6a86b4623ae9f94113d3803707..c5ed6700e0d3d3bbb41046616591feb85c5c1b98 100644 (file)
@@ -80,33 +80,101 @@ zak_cgi_form_element_check_init (ZakCgiFormElementCheck *zak_cgi_form_element_ch
 
 /**
  * zak_cgi_form_element_check_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementCheck object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_check_new ()
+{
+       ZakCgiFormElementCheck *zak_cgi_form_element_check;
+
+       zak_cgi_form_element_check = ZAK_CGI_FORM_ELEMENT_CHECK (g_object_new (zak_cgi_form_element_check_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_check);
+}
+
+/**
+ * zak_cgi_form_element_check_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementCheck object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_check_new (const gchar *id,
-                                                                ...)
+*zak_cgi_form_element_check_new_attrs (const gchar *id,
+                                                                          ...)
 {
        va_list ap;
 
        GHashTable *ht_attrs;
 
-       ZakCgiFormElementCheck *zak_cgi_form_element_check;
+       ZakCgiFormElement *zak_cgi_form_element_check;
 
-       zak_cgi_form_element_check = ZAK_CGI_FORM_ELEMENT_CHECK (g_object_new (zak_cgi_form_element_check_get_type (), NULL));
+       zak_cgi_form_element_check = zak_cgi_form_element_check_new ();
 
        va_start (ap, id);
 
        ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap);
        g_hash_table_replace (ht_attrs, "type", "checkbox");
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_check_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_check),
-                                                                                                                                                                       id,
-                                                                                                                                                                       ht_attrs);
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_check_parent_class)->construct (zak_cgi_form_element_check,
+                                                                                                                                                                        id,
+                                                                                                                                                                        ht_attrs);
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_check);
+       return zak_cgi_form_element_check;
+}
+
+gboolean
+zak_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+       g_hash_table_replace (ht_attrs, "type", "checkbox");
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                               {
+                                       zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_check_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                        id,
+                                                                                                                                                                                        ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
 }
 
 static gchar
index 1d567748ae75c7a11d738f4a64598960cb7e9deb..6fb9ede30f751ef48a8b83b6e5e673e792e2cd0b 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementCheckClass
 
 GType zak_cgi_form_element_check_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_check_new (const gchar *id, ...);
+ZakCgiFormElement *zak_cgi_form_element_check_new (void);
+ZakCgiFormElement *zak_cgi_form_element_check_new_attrs (const gchar *id, ...);
+
+gboolean zak_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index f612eb9f8b5ac7f45b456539d7e6c3b21b2b1229..abf0ce02e8fe3530047b076c4809152248b074b3 100644 (file)
@@ -78,33 +78,98 @@ zak_cgi_form_element_hidden_init (ZakCgiFormElementHidden *zak_cgi_form_element_
 
 /**
  * zak_cgi_form_element_hidden_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementHidden object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_hidden_new ()
+{
+       ZakCgiFormElementHidden *zak_cgi_form_element_hidden;
+
+       zak_cgi_form_element_hidden = ZAK_CGI_FORM_ELEMENT_HIDDEN (g_object_new (zak_cgi_form_element_hidden_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_hidden);
+}
+
+/**
+ * zak_cgi_form_element_hidden_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementHidden object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_hidden_new (const gchar *id,
-                                                                 ...)
+*zak_cgi_form_element_hidden_new_attrs (const gchar *id,
+                                                                               ...)
 {
        va_list ap;
 
        GHashTable *ht_attrs;
 
-       ZakCgiFormElementHidden *zak_cgi_form_element_hidden;
+       ZakCgiFormElement *zak_cgi_form_element_hidden;
 
-       zak_cgi_form_element_hidden = ZAK_CGI_FORM_ELEMENT_HIDDEN (g_object_new (zak_cgi_form_element_hidden_get_type (), NULL));
+       zak_cgi_form_element_hidden = zak_cgi_form_element_hidden_new ();
 
        va_start (ap, id);
 
        ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap);
        g_hash_table_replace (ht_attrs, "type", "hidden");
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_hidden_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_hidden),
-                                                                                                                                                                       id,
-                                                                                                                                                                       ht_attrs);
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_hidden_parent_class)->construct (zak_cgi_form_element_hidden,
+                                                                                                                                                                         id,
+                                                                                                                                                                         ht_attrs);
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_hidden);
+       return zak_cgi_form_element_hidden;
+}
+
+
+gboolean
+zak_cgi_form_element_hidden_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+       g_hash_table_replace (ht_attrs, "type", "hidden");
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_hidden_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                         id,
+                                                                                                                                                                                         ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
 }
 
 static gchar
index 4f9b3de5ddeb44691d15146c44e89a45a1417b75..0ead29eb4c4867a064e7579bc9054d056f870726 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementHiddenClass
 
 GType zak_cgi_form_element_hidden_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_hidden_new (const gchar *id, ...);
+ZakCgiFormElement *zak_cgi_form_element_hidden_new (void);
+ZakCgiFormElement *zak_cgi_form_element_hidden_new_attrs (const gchar *id, ...);
+
+gboolean zak_cgi_form_element_hidden_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index 1797db436d6f1be42d5e3b4e02547ef9c7e9f278..bf066443cdc9b7f80acb1e0787501b7a9c71f383 100644 (file)
@@ -78,33 +78,101 @@ zak_cgi_form_element_password_init (ZakCgiFormElementPassword *zak_cgi_form_elem
 
 /**
  * zak_cgi_form_element_password_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementPassword object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_password_new ()
+{
+       ZakCgiFormElementPassword *zak_cgi_form_element_password;
+
+       zak_cgi_form_element_password = ZAK_CGI_FORM_ELEMENT_PASSWORD (g_object_new (zak_cgi_form_element_password_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_password);
+}
+
+/**
+ * zak_cgi_form_element_password_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementPassword object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_password_new (const gchar *id,
-                                                                       ...)
+*zak_cgi_form_element_password_new_attrs (const gchar *id,
+                                                                                 ...)
 {
        va_list ap;
 
        GHashTable *ht_attrs;
 
-       ZakCgiFormElementPassword *zak_cgi_form_element_password;
+       ZakCgiFormElement *zak_cgi_form_element_password;
 
-       zak_cgi_form_element_password = ZAK_CGI_FORM_ELEMENT_PASSWORD (g_object_new (zak_cgi_form_element_password_get_type (), NULL));
+       zak_cgi_form_element_password = zak_cgi_form_element_password_new ();
 
        va_start (ap, id);
 
        ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap);
        g_hash_table_replace (ht_attrs, "type", "password");
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_password_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_password),
-                                                                                                                                                                       id,
-                                                                                                                                                                       ht_attrs);
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_password_parent_class)->construct (zak_cgi_form_element_password,
+                                                                                                                                                                               id,
+                                                                                                                                                                               ht_attrs);
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_password);
+       return zak_cgi_form_element_password;
+}
+
+gboolean
+zak_cgi_form_element_password_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+       g_hash_table_replace (ht_attrs, "type", "password");
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                               {
+                                       zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_password_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                               id,
+                                                                                                                                                                                               ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
 }
 
 static gchar
index dcba59908de7f64f15deba683cb9c8a2ac01a22d..4b38eff958c4c7ca8864d17c082041200955f57f 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementPasswordClass
 
 GType zak_cgi_form_element_password_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_password_new (const gchar *id,  ...);
+ZakCgiFormElement *zak_cgi_form_element_password_new ();
+ZakCgiFormElement *zak_cgi_form_element_password_new_attrs (const gchar *id, ...);
+
+gboolean zak_cgi_form_element_password_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index 6df66a3e09842ff5aff75019d52a0da14bdcf6f2..4af569a7fdb85e195e9517c0fac63fd9c7d378c2 100644 (file)
@@ -79,28 +79,43 @@ zak_cgi_form_element_select_init (ZakCgiFormElementSelect *zak_cgi_form_element_
 
 /**
  * zak_cgi_form_element_select_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementSelect object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_select_new ()
+{
+       ZakCgiFormElementSelect *zak_cgi_form_element_select;
+
+       zak_cgi_form_element_select = ZAK_CGI_FORM_ELEMENT_SELECT (g_object_new (zak_cgi_form_element_select_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_select);
+}
+
+/**
+ * zak_cgi_form_element_select_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementSelect object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_select_new (const gchar *id,
-                                                                 ...)
+*zak_cgi_form_element_select_new_attrs (const gchar *id,
+                                                                               ...)
 {
        va_list ap;
 
-       ZakCgiFormElementSelect *zak_cgi_form_element_select;
+       ZakCgiFormElement *zak_cgi_form_element_select;
 
-       zak_cgi_form_element_select = ZAK_CGI_FORM_ELEMENT_SELECT (g_object_new (zak_cgi_form_element_select_get_type (), NULL));
+       zak_cgi_form_element_select = zak_cgi_form_element_select_new ();
 
        va_start (ap, id);
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_select_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_select),
-                                                                                                                                                                       id,
-                                                                                                                                                                       zak_cgi_commons_valist_to_ghashtable (ap));
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_select_parent_class)->construct (zak_cgi_form_element_select,
+                                                                                                                                                                         id,
+                                                                                                                                                                         zak_cgi_commons_valist_to_ghashtable (ap));
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_select);
+       return zak_cgi_form_element_select;
 }
 
 /**
@@ -133,6 +148,62 @@ zak_cgi_form_element_select_add_option (ZakCgiFormElementSelect *element,
        g_hash_table_replace (priv->ht_options, g_strdup (value), ht_attrs);
 }
 
+gboolean
+zak_cgi_form_element_select_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                               {
+                                       zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"option") == 0)
+                               {
+                                       zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), (gchar *)xmlGetProp (cur, (xmlChar *)"id"), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_select_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                         id,
+                                                                                                                                                                                         ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
+}
+
 static gchar
 *zak_cgi_form_element_select_render (ZakCgiFormElement *element)
 {
index fdbc4539f0c8f3341332a4dd8191af48560cdf74..23882ef3334d7d85d853efa5621fa9044c6156fb 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,10 +53,13 @@ struct _ZakCgiFormElementSelectClass
 
 GType zak_cgi_form_element_select_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_select_new (const gchar *id, ...);
+ZakCgiFormElement *zak_cgi_form_element_select_new (void);
+ZakCgiFormElement *zak_cgi_form_element_select_new_attrs (const gchar *id, ...);
 
 void zak_cgi_form_element_select_add_option (ZakCgiFormElementSelect *element, const gchar *value, const gchar *content, ...);
 
+gboolean zak_cgi_form_element_select_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
+
 
 G_END_DECLS
 
index 05ef4e4c18fa600da1faed65a8cfb9a9d97ef905..50ca75967a305e2463c27d9d82ccab0e56db3489 100644 (file)
@@ -82,22 +82,65 @@ zak_cgi_form_element_string_init (ZakCgiFormElementString *zak_cgi_form_element_
 
 /**
  * zak_cgi_form_element_string_new:
- * @str:
  *
  * Returns: the newly created #ZakCgiFormElementString object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_string_new (const gchar *str)
+*zak_cgi_form_element_string_new ()
 {
        ZakCgiFormElementString *zak_cgi_form_element_string;
 
        zak_cgi_form_element_string = ZAK_CGI_FORM_ELEMENT_STRING (g_object_new (zak_cgi_form_element_string_get_type (), NULL));
 
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_string);
+}
+
+/**
+ * zak_cgi_form_element_string_new_attrs:
+ * @str:
+ *
+ * Returns: the newly created #ZakCgiFormElementString object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_string_new_attrs (const gchar *str)
+{
+       ZakCgiFormElement *zak_cgi_form_element_string;
+
+       zak_cgi_form_element_string = zak_cgi_form_element_string_new ();
+
        ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string);
 
        priv->str = g_strdup (str);
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_string);
+       return zak_cgi_form_element_string;
+}
+
+gboolean
+zak_cgi_form_element_string_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       xmlNode *cur;
+
+       ZakCgiFormElementStringPrivate *priv;
+
+       ret = FALSE;
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"string") == 0)
+                               {
+                                       priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (ZAK_CGI_FORM_ELEMENT_STRING (element));
+                                       priv->str = g_strdup ((gchar *)xmlNodeGetContent (cur));
+                                       ret = TRUE;
+                                       break;
+                               }
+
+                       cur = cur->next;
+               }
+
+       return ret;
 }
 
 static gchar
index a9db7c33f2e4a085412487c7b608c2995f7f175f..884b52b7001003ea873cf05a5e69001e815d1449 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementStringClass
 
 GType zak_cgi_form_element_string_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_string_new (const gchar *str);
+ZakCgiFormElement *zak_cgi_form_element_string_new (void);
+ZakCgiFormElement *zak_cgi_form_element_string_new_attrs (const gchar *str);
+
+gboolean zak_cgi_form_element_string_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index 0a80ab06e3beac763150b730f54cb801cb35602f..6cc0d3f1e66af112651813fc14c048e1151db300 100644 (file)
@@ -78,28 +78,95 @@ zak_cgi_form_element_submit_init (ZakCgiFormElementSubmit *zak_cgi_form_element_
 
 /**
  * zak_cgi_form_element_submit_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementSubmit object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_submit_new ()
+{
+       ZakCgiFormElementSubmit *zak_cgi_form_element_submit;
+
+       zak_cgi_form_element_submit = ZAK_CGI_FORM_ELEMENT_SUBMIT (g_object_new (zak_cgi_form_element_submit_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_submit);
+}
+
+/**
+ * zak_cgi_form_element_submit_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementSubmit object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_submit_new (const gchar *id,
-                                                                 ...)
+*zak_cgi_form_element_submit_new_attrs (const gchar *id,
+                                                                               ...)
 {
        va_list ap;
 
-       ZakCgiFormElementSubmit *zak_cgi_form_element_submit;
+       ZakCgiFormElement *zak_cgi_form_element_submit;
 
-       zak_cgi_form_element_submit = ZAK_CGI_FORM_ELEMENT_SUBMIT (g_object_new (zak_cgi_form_element_submit_get_type (), NULL));
+       zak_cgi_form_element_submit = zak_cgi_form_element_submit_new ();
 
        va_start (ap, id);
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_submit),
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->construct (zak_cgi_form_element_submit,
                                                                                                                                                                          id,
                                                                                                                                                                          zak_cgi_commons_valist_to_ghashtable (ap));
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_submit);
+       return zak_cgi_form_element_submit;
+}
+
+gboolean
+zak_cgi_form_element_submit_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                               {
+                                       zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                         id,
+                                                                                                                                                                                         ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
 }
 
 static gchar
index 8f71b15af8f70bf58f32a067b26e3974df01fc57..73be7586ee092f02dbb8f395c054bae2ca3ab177 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementSubmitClass
 
 GType zak_cgi_form_element_submit_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_submit_new (const gchar *id, ...);
+ZakCgiFormElement *zak_cgi_form_element_submit_new (void);
+ZakCgiFormElement *zak_cgi_form_element_submit_new_attrs (const gchar *id, ...);
+
+gboolean zak_cgi_form_element_submit_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index 8be61233bd5abaf403903f11fa5f8a20d994991c..425df8bfc4b20407f7e8621c94171eca272b21d3 100644 (file)
@@ -78,28 +78,95 @@ zak_cgi_form_element_text_init (ZakCgiFormElementText *zak_cgi_form_element_text
 
 /**
  * zak_cgi_form_element_text_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementText object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_text_new ()
+{
+       ZakCgiFormElementText *zak_cgi_form_element_text;
+
+       zak_cgi_form_element_text = ZAK_CGI_FORM_ELEMENT_TEXT (g_object_new (zak_cgi_form_element_text_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text);
+}
+
+/**
+ * zak_cgi_form_element_text_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementText object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_text_new (const gchar *id,
-                                                               ...)
+*zak_cgi_form_element_text_new_attrs (const gchar *id,
+                                                                         ...)
 {
        va_list ap;
 
-       ZakCgiFormElementText *zak_cgi_form_element_text;
+       ZakCgiFormElement *zak_cgi_form_element_text;
 
-       zak_cgi_form_element_text = ZAK_CGI_FORM_ELEMENT_TEXT (g_object_new (zak_cgi_form_element_text_get_type (), NULL));
+       zak_cgi_form_element_text = zak_cgi_form_element_text_new ();
 
        va_start (ap, id);
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text),
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_parent_class)->construct (zak_cgi_form_element_text,
                                                                                                                                                                        id,
                                                                                                                                                                        zak_cgi_commons_valist_to_ghashtable (ap));
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text);
+       return zak_cgi_form_element_text;
+}
+
+gboolean
+zak_cgi_form_element_text_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                               {
+                                       zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                       id,
+                                                                                                                                                                                       ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
 }
 
 static gchar
index 5abdfb666fe66468b4f280b076c6541256ce6c73..157e4de3d36b22657ca71886a0306cf601a1ee49 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementTextClass
 
 GType zak_cgi_form_element_text_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_text_new (const gchar *id, ...);
+ZakCgiFormElement *zak_cgi_form_element_text_new (void);
+ZakCgiFormElement *zak_cgi_form_element_text_new_attrs (const gchar *id, ...);
+
+gboolean zak_cgi_form_element_text_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index 49e28e21421240b13ef4ea1ad62d3795be4a6cc9..f62a8db3fc78cbdeebd2becd1c54d066f9c40d37 100644 (file)
@@ -78,28 +78,95 @@ zak_cgi_form_element_text_area_init (ZakCgiFormElementTextArea *zak_cgi_form_ele
 
 /**
  * zak_cgi_form_element_text_area_new:
+ *
+ * Returns: the newly created #ZakCgiFormElementTextArea object.
+ */
+ZakCgiFormElement
+*zak_cgi_form_element_text_area_new ()
+{
+       ZakCgiFormElementTextArea *zak_cgi_form_element_text_area;
+
+       zak_cgi_form_element_text_area = ZAK_CGI_FORM_ELEMENT_TEXT_AREA (g_object_new (zak_cgi_form_element_text_area_get_type (), NULL));
+
+       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text_area);
+}
+
+/**
+ * zak_cgi_form_element_text_area_new_attrs:
  * @id:
  * @...:
  *
  * Returns: the newly created #ZakCgiFormElementTextArea object.
  */
 ZakCgiFormElement
-*zak_cgi_form_element_text_area_new (const gchar *id,
-                                                                        ...)
+*zak_cgi_form_element_text_area_new_attrs (const gchar *id,
+                                                                                  ...)
 {
        va_list ap;
 
-       ZakCgiFormElementTextArea *zak_cgi_form_element_text_area;
+       ZakCgiFormElement *zak_cgi_form_element_text_area;
 
-       zak_cgi_form_element_text_area = ZAK_CGI_FORM_ELEMENT_TEXT_AREA (g_object_new (zak_cgi_form_element_text_area_get_type (), NULL));
+       zak_cgi_form_element_text_area = zak_cgi_form_element_text_area_new ();
 
        va_start (ap, id);
 
-       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_area_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text_area),
+       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_area_parent_class)->construct (zak_cgi_form_element_text_area,
                                                                                                                                                                                 id,
                                                                                                                                                                                 zak_cgi_commons_valist_to_ghashtable (ap));
 
-       return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text_area);
+       return zak_cgi_form_element_text_area;
+}
+
+gboolean
+zak_cgi_form_element_text_area_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode)
+{
+       gboolean ret;
+
+       gchar *id;
+
+       GHashTable *ht_attrs;
+
+       xmlNode *cur;
+
+       id = NULL;
+
+       ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+
+       cur = xmlnode->children;
+       while (cur != NULL)
+               {
+                       if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0)
+                               {
+                                       id = (gchar *)xmlNodeGetContent (cur);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                               {
+                                       zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL);
+                               }
+                       else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0)
+                               {
+                               }
+                       else
+                               {
+                                       g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur));
+                               }
+
+                       cur = cur->next;
+               }
+
+       if (id != NULL)
+               {
+                       ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_area_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element),
+                                                                                                                                                                                                id,
+                                                                                                                                                                                                ht_attrs);
+                       ret = TRUE;
+               }
+       else
+               {
+                       ret = FALSE;
+               }
+
+       return ret;
 }
 
 static gchar
index abbf253de8287ae50a7a4add3244d283c3375165..308fcd6d89728ced912500b59b753a025df99af9 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <glib-object.h>
 
+#include <libxml/tree.h>
+
 #include "formelement.h"
 
 
@@ -51,7 +53,10 @@ struct _ZakCgiFormElementTextAreaClass
 
 GType zak_cgi_form_element_text_area_get_type (void);
 
-ZakCgiFormElement *zak_cgi_form_element_text_area_new (const gchar *id, ...);
+ZakCgiFormElement *zak_cgi_form_element_text_area_new (void);
+ZakCgiFormElement *zak_cgi_form_element_text_area_new_attrs (const gchar *id, ...);
+
+gboolean zak_cgi_form_element_text_area_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode);
 
 
 G_END_DECLS
index 8d64bd96bdeea8dab0b7430ead47260735edc4be..efa6046aaae504e88e68523869a4173be4ceda84 100644 (file)
@@ -650,14 +650,14 @@ GHashTable
 }
 
 /**
- * zak_cgi_main_get_param:
+ * zak_cgi_main_get_parameter:
  * @zakcgimain:
  * @param:
  *
  * Returns:
  */
 GValue
-*zak_cgi_main_get_param  (ZakCgiMain *zakcgimain, const gchar *param)
+*zak_cgi_main_get_parameter  (ZakCgiMain *zakcgimain, const gchar *param)
 {
        ZakCgiMainPrivate *priv;
 
index e24b71eaa13c16287d1d7a1d7fde45a5135a04b1..27b6b1c078ac3876347646122f0179c707e2d024 100644 (file)
@@ -80,7 +80,7 @@ gchar *zak_cgi_main_set_cookie (const gchar *name,
 
 G_DEPRECATED_FOR (zak_cgi_main_get_parameter)
 GHashTable *zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string);
-gchar *zak_cgi_main_get_parameter (ZakCgiMain *zakcgimain, const gchar *param);
+GValue *zak_cgi_main_get_parameter (ZakCgiMain *zakcgimain, const gchar *param);
 void zak_cgi_main_parameters_foreach (ZakCgiMain *zakcgimain, GHFunc func, gpointer user_data);
 
 
index 6a2552d0b70c39570a369fedcee1c7d8a42b30b3..c888c63833fe35b971eac7b093058f9933cbbb91 100644 (file)
@@ -12,8 +12,12 @@ noinst_PROGRAMS = \
                     cookies \
                     env \
                     form \
+                    form_xml \
                     querystring \
                     redirect \
                     session \
                     tag \
                     url
+
+EXTRA_DIST = \
+             form_xml.xml
index 2cfad21b10843bd860be8d89db449572f1232354..09c722acc793844fdf45302f3cb18f40b5fc96ef 100644 (file)
@@ -62,7 +62,7 @@ main (int argc, char *argv[])
                                                         "action", "form",
                                                         NULL);
 
-       element = zak_cgi_form_element_text_new ("first", NULL);
+       element = zak_cgi_form_element_text_new_attrs ("first", NULL);
        zak_cgi_form_element_set_label (element, "The Label for first", NULL);
        zak_form_element_add_filter (ZAK_FORM_ELEMENT (element),
                                                                 ZAK_FORM_ELEMENT_FILTER (zak_form_element_filter_trim_new ()));
@@ -70,31 +70,31 @@ main (int argc, char *argv[])
                                                                        ZAK_FORM_ELEMENT_VALIDATOR (zak_form_element_validator_regex_new ("^aaa$")));
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_check_new ("chk", NULL);
+       element = zak_cgi_form_element_check_new_attrs ("chk", NULL);
        zak_cgi_form_element_set_label (element, "The checkbox", NULL);
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_string_new ("<h1>big big big</h1>");
+       element = zak_cgi_form_element_string_new_attrs ("<h1>big big big</h1>");
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_password_new ("pws", NULL);
+       element = zak_cgi_form_element_password_new_attrs ("pws", NULL);
        zak_cgi_form_element_set_label (element, "The password", NULL);
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_text_area_new ("txtarea", NULL);
+       element = zak_cgi_form_element_text_area_new_attrs ("txtarea", NULL);
        zak_cgi_form_element_set_label (element, "The text area", NULL);
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_select_new ("slc", NULL);
+       element = zak_cgi_form_element_select_new_attrs ("slc", NULL);
        zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), "1", "first", NULL);
        zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), "2", "second", NULL);
        zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), "3", "third", NULL);
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_hidden_new ("hdn", NULL);
+       element = zak_cgi_form_element_hidden_new_attrs ("hdn", NULL);
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
-       element = zak_cgi_form_element_submit_new ("submit", "zak-cgi-content", "Submit", NULL);
+       element = zak_cgi_form_element_submit_new_attrs ("submit", "zak-cgi-content", "Submit", NULL);
        zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
 
        if (zak_cgi_main_is_post (zakcgimain))
diff --git a/tests/form_xml.c b/tests/form_xml.c
new file mode 100644 (file)
index 0000000..517c903
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <unistd.h>
+
+#include <libzakform/libzakform.h>
+
+#include <form.h>
+#include <formelement.h>
+#include <formelementcheck.h>
+#include <formelementhidden.h>
+#include <formelementpassword.h>
+#include <formelementselect.h>
+#include <formelementstring.h>
+#include <formelementtext.h>
+#include <formelementtextarea.h>
+#include <formelementsubmit.h>
+
+int
+main (int argc, char *argv[])
+{
+       ZakCgiMain *zakcgimain;
+
+       GString *str;
+
+       ZakCgiForm *form;
+       ZakCgiFormElement *element;
+
+       zakcgimain = zak_cgi_main_new ();
+
+       str = g_string_new ("<!DOCTYPE html>\n"
+                                               "<html lang=\"it\">\n"
+                                               "<head>\n"
+                                               "<meta charset=\"utf-8\">\n"
+                                               "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n"
+                                               "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
+                                               "<title>Form test</title>\n"
+                                               "<!-- Bootstrap -->\n"
+                                               "<!-- Latest compiled and minified CSS -->\n"
+                                               "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n"
+                                               "</head>\n"
+                                               "<body>\n"
+                                               "<div class=\"container\">\n");
+
+       form = zak_cgi_form_new (zakcgimain,
+                                                        "method", "post",
+                                                        "action", "form",
+                                                        NULL);
+
+    GValue *val = zak_cgi_main_get_parameter (zakcgimain, "filename");
+       if (zak_form_form_load_from_file (ZAK_FORM_FORM (form), g_value_get_string (val)))
+               {
+                       if (zak_cgi_main_is_post (zakcgimain))
+                               {
+                                       /* validating the form */
+                                       zak_cgi_form_bind (form);
+                                       if (zak_form_form_is_valid (ZAK_FORM_FORM (form)))
+                                               {
+                                                       g_string_append (str, "Form is valid!!!");
+                                               }
+                                       else
+                                               {
+                                                       g_string_append (str, zak_cgi_form_render (form));
+                                                       g_string_append (str, "Form is not valid!!!");
+                                               }
+                               }
+                       else
+                               {
+                                       g_string_append (str, zak_cgi_form_render (form));
+                               }
+               }
+
+       g_string_append (str,
+                                        "\n</div>\n"
+                                        "<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->\n"
+                                        "<script src=\"http://code.jquery.com/jquery-1.11.3.min.js\"></script>\n"
+                                        "<!-- Include all compiled plugins (below), or include individual files as needed -->\n"
+                                        "<!-- Latest compiled and minified JavaScript -->\n"
+                                        "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\"></script>\n"
+                                        "</body>\n"
+                                        "</html>");
+
+       zak_cgi_main_out (NULL, str->str);
+
+       return 0;
+}
diff --git a/tests/form_xml.xml b/tests/form_xml.xml
new file mode 100644 (file)
index 0000000..34ef91f
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<zakform>
+
+  <element type="zak_cgi_form_element_text">
+       <id>first</id>
+       <label>The Label for first</label>
+  </element>
+
+  <element type="zak_cgi_form_element_check">
+       <id>chk</id>
+       <label>The checkbox</label>
+  </element>
+
+  <element type="zak_cgi_form_element_string">
+       <string>&lt;h1&gt;big big big&lt;/h1&gt;</string>
+  </element>
+
+  <element type="zak_cgi_form_element_password">
+       <id>pws</id>
+       <label>The password</label>
+  </element>
+
+  <element type="zak_cgi_form_element_text_area">
+       <id>txtarea</id>
+       <label>The Text Area</label>
+  </element>
+
+  <element type="zak_cgi_form_element_select">
+       <id>slc</id>
+       <option id="1">first</option>
+       <option id="2">second</option>
+       <option id="3">third</option>
+  </element>
+
+  <element type="zak_cgi_form_element_hidden">
+       <id>hdn</id>
+  </element>
+
+  <element type="zak_cgi_form_element_submit">
+       <id>submit</id>
+       <zak-cgi-content>Submit</zak-cgi-content>
+  </element>
+
+</zakform>
index 7316cb13347aca711b19d8736a84996b02c3972f..c1ad2ab11cdc18aec4cab7a529dde2ccd58e5776 100644 (file)
@@ -64,11 +64,11 @@ main (int argc, char *argv[])
 
        g_string_append_printf (str,
                                                        "<tr><td>IS GET?</td><td>%s</td></tr>\n",
-                                                       zak_cgi_main_is_get (NULL) ? "TRUE" : "FALSE");
+                                                       zak_cgi_main_is_get (main) ? "TRUE" : "FALSE");
 
        g_string_append_printf (str,
                                                        "<tr><td>IS POST?</td><td>%s</td></tr>\n",
-                                                       zak_cgi_main_is_post (NULL) ? "TRUE" : "FALSE");
+                                                       zak_cgi_main_is_post (main) ? "TRUE" : "FALSE");
 
        zak_cgi_main_parameters_foreach (main, ht_foreach, str);