]> saetta.ns0.it Git - zakform/cgi/commitdiff
Starting taking into account ZakFormElementArray. array
authorAndrea Zagli <azagli@libero.it>
Sat, 17 Jun 2017 09:50:55 +0000 (11:50 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 17 Jun 2017 09:50:55 +0000 (11:50 +0200)
src/form.c
src/formelement.c

index debf1d432cfd1f81ed46c624b2a1e8b08c7d4b7f..e3163ed0b83f735145692c4eb384ca7f2de85d56 100644 (file)
@@ -185,6 +185,28 @@ get_idx (ZakFormCgiForm *zakcgiform, const gchar *id)
        return idx;
 }
 
+static void
+_zak_form_cgi_form_bind (ZakFormCgiFormPrivate *priv, ZakFormCgiFormElement *element)
+{
+       gchar *id;
+       GValue *gval;
+
+       id = zak_form_cgi_form_element_get_id (element);
+       if (id != NULL)
+               {
+                       gval = zak_cgi_main_get_stdin_field (priv->zakcgimain, id);
+                       if (gval != NULL)
+                               {
+                                       zak_form_cgi_form_element_bind (element, gval);
+                               }
+                       g_free (id);
+               }
+       else
+               {
+                       g_warning (_("Element without id."));
+               }
+}
+
 /**
  * zak_form_cgi_form_bind:
  * @zakcgiform:
@@ -195,8 +217,6 @@ zak_form_cgi_form_bind (ZakFormCgiForm *zakcgiform)
 {
        guint i;
 
-       GValue *gval;
-
        ZakFormCgiFormPrivate *priv;
 
        g_return_if_fail (ZAK_FORM_CGI_IS_FORM (zakcgiform));
@@ -208,10 +228,20 @@ zak_form_cgi_form_bind (ZakFormCgiForm *zakcgiform)
                        ZakFormCgiFormElement *element = (ZakFormCgiFormElement *)g_ptr_array_index (priv->ar_elems, i);
                        if (!ZAK_FORM_CGI_IS_FORM_ELEMENT_STRING (element))
                                {
-                                       gval = zak_cgi_main_get_stdin_field (priv->zakcgimain, zak_form_cgi_form_element_get_id (element));
-                                       if (gval != NULL)
+                                       if (ZAK_FORM_IS_ELEMENT_ARRAY ((ZAK_FORM_ELEMENT (element))))
+                                               {
+                                                       GPtrArray *ar_elements;
+                                                       guint l;
+
+                                                       ar_elements = zak_form_element_array_get_elements (ZAK_FORM_ELEMENT_ARRAY (element));
+                                                       for (l = 0; l < ar_elements->len; l++)
+                                                               {
+                                                                       _zak_form_cgi_form_bind (priv, (ZakFormCgiFormElement *)g_ptr_array_index (ar_elements, l));
+                                                               }
+                                               }
+                                       else
                                                {
-                                                       zak_form_cgi_form_element_bind (element, gval);
+                                                       _zak_form_cgi_form_bind (priv, element);
                                                }
                                }
                }
@@ -275,9 +305,26 @@ gchar
        for (i = 0; i < priv->ar_elems->len; i++)
                {
                        ZakFormCgiFormElement *element = (ZakFormCgiFormElement *)g_ptr_array_index (priv->ar_elems, i);
-                       tmp = zak_form_cgi_form_element_render (element);
-                       g_string_append_printf (str, "\n%s", tmp);
-                       g_free (tmp);
+
+                       if (ZAK_FORM_IS_ELEMENT_ARRAY (element))
+                               {
+                                       GPtrArray *ar_elements;
+                                       guint l;
+
+                                       ar_elements = zak_form_element_array_get_elements (ZAK_FORM_ELEMENT (element));
+                                       for (l = 0; l < ar_elements->len; l++)
+                                               {
+                                                       tmp = zak_form_cgi_form_element_render ((ZakFormCgiFormElement *)g_ptr_array_index (ar_elements, l));
+                                                       g_string_append_printf (str, "\n%s", tmp);
+                                                       g_free (tmp);
+                                               }
+                               }
+                       else
+                               {
+                                       tmp = zak_form_cgi_form_element_render (element);
+                                       g_string_append_printf (str, "\n%s", tmp);
+                                       g_free (tmp);
+                               }
                }
 
        g_string_append (str, "\n</form>");
index ce1415756096a6ff514b40819cd37a450f781179..922406fff47749f653b83c0d3c0376a657b30217 100644 (file)
@@ -196,7 +196,10 @@ gchar
 
        g_string_append (str, "\">\n");
 
-       g_string_append (str, zak_form_cgi_form_element_render_label (element));
+       if (ZAK_FORM_CGI_IS_FORM_ELEMENT (element))
+               {
+                       g_string_append (str, zak_form_cgi_form_element_render_label (element));
+               }
 
        if (ZAK_FORM_CGI_IS_FORM_ELEMENT (element) && ZAK_FORM_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL)
                {