diff options
Diffstat (limited to 'form_post.c')
| -rw-r--r-- | form_post.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/form_post.c b/form_post.c new file mode 100644 index 0000000..c485a55 --- /dev/null +++ b/form_post.c @@ -0,0 +1,54 @@ +#define _POSIX_C_SOURCE 200809L + +#include "form.h" +#include <libweb/html.h> +#include <stdio.h> + +int form_post(struct html_node *const n, const unsigned long category, + const unsigned long section, const unsigned long topic) +{ + int ret = -1; + struct dynstr d; + struct html_node *div, *form, *textarea, *submit; + + dynstr_init(&d); + + if (dynstr_append(&d, "/create/%lu/%lu/%lu", category, section, topic)) + { + 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")) + || !(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(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(textarea, "")) + { + fprintf(stderr, "%s: html_node_set_value failed\n", __func__); + goto end; + } + + ret = 0; + +end: + dynstr_free(&d); + return ret; +} |
