]> saetta.ns0.it Git - zakform/cgi/commitdiff
If no ZakFormCgiElement name before rendering, it tries to get it from ZakFormElement...
authorAndrea Zagli <azagli@libero.it>
Sat, 7 Sep 2019 12:35:45 +0000 (14:35 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 7 Sep 2019 12:35:45 +0000 (14:35 +0200)
src/formelement.c

index 0a5d0edbc163723829ec35223212d20abd07e802..a7858dcf5d08193ccf45761e9ce98b77239203b4 100644 (file)
@@ -179,6 +179,8 @@ gchar
 
        guint i;
 
+       gchar *name;
+
        gchar *attr_class;
 
        ZakFormCgiFormElementPrivate *priv;
@@ -188,7 +190,7 @@ gchar
        if (priv->id == NULL
            || g_strcmp0 (g_strstrip (priv->id), "") == 0)
                {
-                       priv->id = g_strdup_printf ("id_%d", g_random_int ());
+                       priv->id = g_strdup_printf ("id_%d", g_random_int_range (0, G_MAXINT));
                }
 
        str = g_string_new ("<div class=\"form-group");
@@ -219,6 +221,27 @@ gchar
                                        priv->ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
                                }
 
+                       name = g_hash_table_lookup (priv->ht_attrs, "name");
+                       if (name == NULL
+                           || g_strcmp0 (g_strstrip (name), "") == 0)
+                               {
+                                       if (name != NULL)
+                                               {
+                                                       g_free (name);
+                                               }
+
+                                       name = zak_form_element_get_name (ZAK_FORM_ELEMENT (element));
+                                       if (name != NULL
+                                           && g_strcmp0 (g_strstrip (name), "") != 0)
+                                               {
+                                                       g_hash_table_insert (priv->ht_attrs, g_strdup ("name"), g_strdup (name));
+                                               }
+                                       if (name != NULL)
+                                               {
+                                                       g_free (name);
+                                               }
+                               }
+
                        attr_class = g_hash_table_lookup (priv->ht_attrs, "class");
                        if (attr_class != NULL)
                                {