struct _ZakCgiFormPrivate
{
ZakCgiMain *zakcgimain;
+ GHashTable *ht_elems;
};
G_DEFINE_TYPE (ZakCgiForm, zak_cgi_form, G_TYPE_OBJECT)
ZakCgiFormPrivate *priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form);
priv->zakcgimain = NULL;
+ priv->ht_elems = g_hash_table_new (g_str_hash, g_str_equal);
}
/**
return zak_cgi_form;
}
+/**
+ * zak_cgi_form_add_element:
+ * @zakcgiform:
+ * @element:
+ *
+ * Returns: #TRUE if @element is added; FALSE otherwise.
+ */
+gboolean
+zak_cgi_form_add_element (ZakCgiForm *zakcgiform, ZakCgiFormElement *element)
+{
+ gboolean ret;
+ gchar *id;
+
+ ZakCgiFormPrivate *priv;
+
+ priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform);
+
+ id = zak_cgi_form_element_get_id (element);
+
+ if (g_hash_table_lookup (priv->ht_elems, id))
+ {
+ g_warning ("You cannot add an element with id already present in the form.");
+ ret = FALSE;
+ }
+ else
+ {
+ g_hash_table_insert (priv->ht_elems, g_strdup (id), element);
+ ret = TRUE;
+ }
+
+ g_free (id);
+
+ return ret;
+}
+
/* PRIVATE */
static void
zak_cgi_form_set_property (GObject *object,
#include <glib-object.h>
#include "main.h"
+#include "formelement.h"
G_BEGIN_DECLS
ZakCgiForm *zak_cgi_form_new (ZakCgiMain *zakcgimain);
+gboolean zak_cgi_form_add_element (ZakCgiForm *zakcgiform, ZakCgiFormElement *element);
+
G_END_DECLS
return zak_cgi_form_element;
}
+gchar
+*zak_cgi_form_element_get_id (ZakCgiFormElement *element)
+{
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ return g_strdup (priv->id);
+}
+
void
zak_cgi_form_element_set_validation_regex (ZakCgiFormElement *element, const gchar *validation_regex)
{
ZakCgiFormElement *zak_cgi_form_element_new (const gchar *id, const gchar *validation_regex, ...);
+gchar *zak_cgi_form_element_get_id (ZakCgiFormElement *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);