priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
- str = g_string_new ("");
+ str = g_string_new ("<div class=\"form-group\">\n");
if (priv->ht_label_attrs != NULL)
{
if (ZAK_CGI_IS_FORM_ELEMENT (element) && ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL)
{
+ gchar *attr_class;
+
+ attr_class = g_hash_table_lookup (priv->ht_attrs, "class");
+ if (attr_class != NULL)
+ {
+ if (g_strstr_len (attr_class, -1, "form-control") == NULL)
+ {
+ g_hash_table_insert (priv->ht_attrs, "class", g_strdup_printf ("%s form-control", attr_class));
+ }
+ g_free (attr_class);
+ }
+ else
+ {
+ g_hash_table_replace (priv->ht_attrs, g_strdup ("class"), g_strdup ("form-control"));
+ }
+
g_string_append (str, ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render (element));
}
+ g_string_append (str, "\n</div>\n");
+
ret = g_strdup (str->str);
g_string_free (str, TRUE);
gchar *ret;
GHashTable *ht_attrs;
+ gchar *attr_class;
+ GString *str_attr_class;
+ gchar *form_control;
ZakCgiFormElementClass *klass;
ht_attrs = klass->get_ht_attrs (element);
+ attr_class = g_hash_table_lookup (ht_attrs, "class");
+ if (attr_class != NULL)
+ {
+ str_attr_class = g_string_new (attr_class);
+ form_control = g_strstr_len (str_attr_class->str, -1, "form-control");
+ if (form_control != NULL)
+ {
+ /* no form-control for submit button */
+ g_string_erase (str_attr_class, form_control - str_attr_class->str, 12);
+ }
+ g_string_free (str_attr_class, TRUE);
+
+ if (g_strstr_len (attr_class, -1, "btn btn-default") == NULL)
+ {
+ g_hash_table_insert (ht_attrs, "class", g_strdup_printf ("%s btn btn-default", str_attr_class->str));
+ }
+
+ g_free (attr_class);
+ }
+ else
+ {
+ g_hash_table_replace (ht_attrs, g_strdup ("class"), g_strdup ("btn btn-default"));
+ }
+
ret = zak_cgi_tag_submit_ht (zak_cgi_form_element_get_id (element), ht_attrs);
return ret;
*/
gchar
*zak_cgi_tag_file_ht (const gchar *id,
- GHashTable *ht)
+ GHashTable *ht)
{
g_hash_table_insert (ht, "type", "file");
ht = zak_cgi_commons_valist_to_ghashtable (ap);
g_hash_table_insert (ht, "type", "submit");
- return zak_cgi_tag_tag_attrs ("input", id, ht);
+ return zak_cgi_tag_tag_attrs ("button", id, ht);
}
{
g_hash_table_insert (ht, "type", "submit");
- return zak_cgi_tag_tag_attrs ("input", id, ht);
+ return zak_cgi_tag_tag_attrs ("button", id, ht);
}
zakcgimain = zak_cgi_main_new ();
- str = g_string_new ("<html>\n"
- "<head><title>Form test</title></head>\n"
- "<body>\n");
+ 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",
element = zak_cgi_form_element_hidden_new ("hdn", "aaa", NULL);
zak_cgi_form_add_element (form, element);
- element = zak_cgi_form_element_submit_new ("submit", "aaa", NULL);
+ element = zak_cgi_form_element_submit_new ("submit", NULL, "zak-cgi-content", "Submit", NULL);
zak_cgi_form_add_element (form, element);
if (zak_cgi_main_is_post (zakcgimain))
g_string_append (str, zak_cgi_form_render (form));
}
- g_string_append (str, "\n</body>");
+ 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);