while (g_hash_table_iter_next (&iter, &key, &value))
{
g_string_append_printf (str,
- " \"%s\"=\"%s\"",
+ " %s=\"%s\"",
(gchar *)key,
(gchar *)value);
}
return ret;
}
+/**
+ * zak_cgi_form_bind:
+ * @zakcgiform:
+ *
+ */
+void
+zak_cgi_form_bind (ZakCgiForm *zakcgiform)
+{
+ GHashTableIter iter;
+ gpointer key;
+ gpointer value;
+
+ GValue *gval;
+
+ ZakCgiFormPrivate *priv;
+
+ g_return_if_fail (ZAK_CGI_IS_FORM (zakcgiform));
+
+ priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform);
+
+ g_hash_table_iter_init (&iter, priv->ht_elems);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ if (!g_str_has_prefix ((gchar *)key, "{id_"))
+ {
+ gval = zak_cgi_main_get_stdin_field (priv->zakcgimain, (gchar *)key);
+ if (gval != NULL)
+ {
+ zak_cgi_form_element_set_value ((ZakCgiFormElement *)value, gval);
+ }
+ }
+ }
+}
+
/**
* zak_cgi_form_render_start:
* @zakcgiform:
ZakCgiFormPrivate *priv;
+ g_return_if_fail (ZAK_CGI_IS_FORM (zakcgiform));
+
priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform);
str = g_string_new ("<form");
gboolean zak_cgi_form_add_element (ZakCgiForm *zakcgiform, ZakCgiFormElement *element);
gboolean zak_cgi_form_add_str (ZakCgiForm *zakcgiform, const gchar *str);
+void zak_cgi_form_bind (ZakCgiForm *zakcgiform);
+
gchar *zak_cgi_form_render_start (ZakCgiForm *zakcgiform);
gchar *zak_cgi_form_render (ZakCgiForm *zakcgiform);
gchar *id;
gchar *validation_regex;
GHashTable *ht_attrs;
+ GValue *value;
};
G_DEFINE_TYPE (ZakCgiFormElement, zak_cgi_form_element, G_TYPE_OBJECT)
return ret;
}
+/**
+ * zak_cgi_form_element_set_value:
+ * @element:
+ * @value:
+ *
+ */
+void
+zak_cgi_form_element_set_value (ZakCgiFormElement *element, GValue *value)
+{
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ priv->value = value;
+}
+
+/**
+ * zak_cgi_form_element_get_value:
+ * @element:
+ *
+ */
+GValue
+*zak_cgi_form_element_get_value (ZakCgiFormElement *element)
+{
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ return priv->value;
+}
+
/**
* zak_cgi_form_element_render:
* @element:
void zak_cgi_form_element_set_validation_regex (ZakCgiFormElement *element, const gchar *validation_regex);
gchar *zak_cgi_form_element_get_validation_regex (ZakCgiFormElement *element);
+void zak_cgi_form_element_set_value (ZakCgiFormElement *element, GValue *value);
+GValue *zak_cgi_form_element_get_value (ZakCgiFormElement *element);
+
gchar *zak_cgi_form_element_render (ZakCgiFormElement *element);
gboolean zak_cgi_form_element_is_valid (ZakCgiFormElement *element);
int
main (int argc, char *argv[])
{
+ ZakCgiMain *zakcgimain;
+
GString *str;
ZakCgiForm *form;
ZakCgiFormElement *element;
- form = zak_cgi_form_new (NULL,
+ zakcgimain = zak_cgi_main_new ();
+
+ str = g_string_new ("<html>\n"
+ "<head><title>Form test</title></head>\n"
+ "<body>\n");
+
+ form = zak_cgi_form_new (zakcgimain,
"method", "post",
+ "action", "form",
NULL);
- str = g_string_new ("");
-
element = zak_cgi_form_element_text_new ("first", "aaa", NULL);
zak_cgi_form_add_element (form, element);
element = zak_cgi_form_element_submit_new ("submit", "aaa", NULL);
zak_cgi_form_add_element (form, element);
- g_string_append (str, zak_cgi_form_render (form));
+ if (zak_cgi_main_is_post (zakcgimain))
+ {
+ /* validating the form */
+ }
+ else
+ {
+ g_string_append (str, zak_cgi_form_render (form));
+ }
+
+ g_string_append (str, "\n</body>");
zak_cgi_main_out (NULL, str->str);