aboutsummaryrefslogtreecommitdiff
path: root/form_topic.c
blob: ffd67eba57f2d7915f2faad227dddecc361d383b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define _POSIX_C_SOURCE 200809L

#include "form.h"
#include <libweb/html.h>
#include <stdio.h>

int form_topic(struct html_node *const n, const unsigned long category,
    const unsigned long section)
{
    int ret = -1;
    struct dynstr d;
    struct html_node *div, *form, *lname, *iname, *textarea, *submit;

    dynstr_init(&d);

    if (dynstr_append(&d, "/create/%lu/%lu", category, section))
    {
        fprintf(stderr, "%s: dynstr_append failed\n", __func__);
        goto end;
    }
    else if (!(div = html_node_add_child(n, "div"))
        || !(form = html_node_add_child(div, "form"))
        || !(lname = html_node_add_child(form, "label"))
        || !(iname = html_node_add_child(form, "input"))
        || !(textarea = html_node_add_child(form, "textarea"))
        || !(submit = html_node_add_child(form, "input")))
    {
        fprintf(stderr, "%s: html_node_add_child failed\n", __func__);
        goto end;
    }
    else if (html_node_add_attr(form, "action", d.str)
        || html_node_add_attr(form, "form", "topicform")
        || html_node_add_attr(form, "method", "post")
        || html_node_add_attr(lname, "for", "name")
        || html_node_add_attr(iname, "type", "text")
        || html_node_add_attr(iname, "id", "name")
        || html_node_add_attr(iname, "name", "name")
        || html_node_add_attr(iname, "hint", "Topic name")
        || html_node_add_attr(iname, "size", "50")
        || html_node_add_attr(textarea, "id", "post")
        || html_node_add_attr(textarea, "name", "post")
        || html_node_add_attr(textarea, "maxlength", "1800")
        || html_node_add_attr(textarea, "cols", "72")
        || html_node_add_attr(textarea, "rows", "8")
        || html_node_add_attr(submit, "type", "submit")
        || html_node_add_attr(submit, "value", "Create"))
    {
        fprintf(stderr, "%s: html_node_add_attr failed\n", __func__);
        goto end;
    }
    else if (html_node_set_value(lname, "Topic name")
        || html_node_set_value(textarea, ""))
    {
        fprintf(stderr, "%s: html_node_set_value failed\n", __func__);
        goto end;
    }

    ret = 0;

end:
    dynstr_free(&d);
    return ret;
}