diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-09-22 17:32:44 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-13 09:57:39 +0100 |
| commit | 78bf2fe4a5bf37514f6dfd203ef969da0bf40c2e (patch) | |
| tree | 33f9440b8ee0fa7a3b3ad033616d722d2101bb4d /form_section.c | |
| parent | 107a2e43d54f9a42fb85b00b83cb0d9abb194680 (diff) | |
Diffstat (limited to 'form_section.c')
| -rw-r--r-- | form_section.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/form_section.c b/form_section.c new file mode 100644 index 0000000..d0bf0b1 --- /dev/null +++ b/form_section.c @@ -0,0 +1,64 @@ +#define _POSIX_C_SOURCE 200809L + +#include "form.h" +#include <libweb/html.h> +#include <stdio.h> + +int form_section(struct html_node *const n, const unsigned long category) +{ + int ret = -1; + struct dynstr d; + struct html_node *div, *form, *lname, *iname, *ltitle, *ititle, *submit; + + dynstr_init(&d); + + if (dynstr_append(&d, "/create/%lu", category)) + { + 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")) + || !(ltitle = html_node_add_child(form, "label")) + || !(ititle = html_node_add_child(form, "input")) + || !(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", "sectionform") + || 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", "Section name") + || html_node_add_attr(iname, "size", "40") + || html_node_add_attr(ltitle, "for", "description") + || html_node_add_attr(ititle, "type", "text") + || html_node_add_attr(ititle, "id", "title") + || html_node_add_attr(ititle, "name", "description") + || html_node_add_attr(ititle, "hint", "Section description") + || html_node_add_attr(ititle, "size", "72") + || 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, "Section name") + || html_node_set_value(ltitle, "Section description")) + { + fprintf(stderr, "%s: html_node_set_value failed\n", __func__); + goto end; + } + + ret = 0; + +end: + dynstr_free(&d); + return ret; +} |
