Handling onsubmit
[elinks.git] / src / document / forms.h
blob601e8e2e1c30d97bfc450cc0485260ee28c9a574
1 #ifndef EL__DOCUMENT_FORMS_H
2 #define EL__DOCUMENT_FORMS_H
4 #include "util/lists.h"
6 struct document;
7 struct menu_item;
11 enum form_method {
12 FORM_METHOD_GET,
13 FORM_METHOD_POST,
14 FORM_METHOD_POST_MP,
15 FORM_METHOD_POST_TEXT_PLAIN,
18 struct form {
19 LIST_HEAD(struct form);
21 /* The value of @form_num serves both as a unique ID of the form.
22 * However @form_num and @form_end also stores information about where
23 * in the source the form is positioned. Combined they are used to
24 * figured which form items belong to which forms after rendering
25 * tables.
27 * Initially the range between @form_num and @form_end will stretch from
28 * 0 to INT_MAX. When a new form is added the range is partitioned so
29 * the forms each has unique source ranges. */
30 int form_num;
31 int form_end;
33 unsigned char *action;
34 unsigned char *name;
35 unsigned char *onsubmit;
36 unsigned char *target;
37 enum form_method method;
39 struct list_head items; /* -> struct form_control */
44 enum form_type {
45 FC_TEXT,
46 FC_PASSWORD,
47 FC_FILE,
48 FC_TEXTAREA,
49 FC_CHECKBOX,
50 FC_RADIO,
51 FC_SELECT,
52 FC_SUBMIT,
53 FC_IMAGE,
54 FC_RESET,
55 FC_BUTTON,
56 FC_HIDDEN,
59 enum form_mode {
60 FORM_MODE_NORMAL,
61 FORM_MODE_READONLY,
62 FORM_MODE_DISABLED,
65 #define form_field_is_readonly(field) ((field)->mode != FORM_MODE_NORMAL)
67 enum form_wrap {
68 FORM_WRAP_NONE,
69 FORM_WRAP_SOFT,
70 FORM_WRAP_HARD,
73 struct form_control {
74 LIST_HEAD(struct form_control);
76 struct form *form;
77 int g_ctrl_num;
79 /* The value of @position is relative to the place of the form item in
80 * the source. */
81 int position;
83 enum form_type type;
84 enum form_mode mode;
86 unsigned char *name;
87 unsigned char *alt;
88 unsigned char *default_value;
89 int default_state;
90 int size;
91 int cols, rows;
92 enum form_wrap wrap;
93 int maxlength;
94 int nvalues;
95 unsigned char **values;
96 unsigned char **labels;
97 struct menu_item *menu;
100 /* Numerical form type <-> form type name */
101 int str2form_type(unsigned char *s);
102 unsigned char *form_type2str(enum form_type num);
104 struct form *init_form(void);
105 void done_form(struct form *form);
106 int has_form_submit(struct form *form);
108 int get_form_control_link(struct document *document, struct form_control *fc);
109 void done_form_control(struct form_control *fc);
111 #endif