From: Andrea Zagli Date: Sat, 17 Jun 2017 09:50:55 +0000 (+0200) Subject: Starting taking into account ZakFormElementArray. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=5326efbafb2fb26c3f5dff62c336e15adbbd7f03;p=zakform%2Fcgi Starting taking into account ZakFormElementArray. --- diff --git a/src/form.c b/src/form.c index debf1d4..e3163ed 100644 --- a/src/form.c +++ b/src/form.c @@ -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"); diff --git a/src/formelement.c b/src/formelement.c index ce14157..922406f 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -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) {