From: Andrea Zagli Date: Mon, 27 Jul 2015 19:26:07 +0000 (+0200) Subject: ZakCgiTag: now id can be null. X-Git-Tag: v0.0.1~10 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=2cdff59ed69f02ec9aacd27cd13604c00d2d5986;p=libzakcgi ZakCgiTag: now id can be null. Added a sample how to make a select element with options. --- diff --git a/src/tag.c b/src/tag.c index 2330778..779fd32 100644 --- a/src/tag.c +++ b/src/tag.c @@ -74,9 +74,15 @@ static gchar str = g_string_new (""); g_string_append_printf (str, - "<%s id=\"%s\"", - name, - id); + "<%s", + name); + + if (id != NULL) + { + g_string_append_printf (str, + " id=\"%s\"", + id); + } l = ar_attrs->len; for (i = 0; i < l; i++) @@ -121,7 +127,8 @@ static gchar } } - if (!with_name) + if (!with_name + && id != NULL) { g_string_append_printf (str, " name=\"%s\"", diff --git a/tests/tag.c b/tests/tag.c index 5030f27..73f4187 100644 --- a/tests/tag.c +++ b/tests/tag.c @@ -22,6 +22,7 @@ int main (int argc, char *argv[]) { GString *str; + GString *select_content; str = g_string_new (""); @@ -41,6 +42,24 @@ main (int argc, char *argv[]) g_string_append_printf (str, "%s
\n", zak_cgi_tag_submit ("submit", NULL)); + select_content = g_string_new (""); + g_string_append_printf (select_content, + zak_cgi_tag_tag ("option", NULL, + "value", "1", + "content", "One", + NULL)); + g_string_append_printf (select_content, + zak_cgi_tag_tag ("option", NULL, + "value", "2", + "content", "Two", + NULL)); + g_string_append_printf (select_content, + zak_cgi_tag_tag ("option", NULL, + "value", "3", + "content", "Three", + NULL)); + g_string_append_printf (str, "%s
\n", zak_cgi_tag_tag ("select", "idselect", "content", select_content->str, NULL)); + zak_cgi_main_out (NULL, str->str); return 0;