]> gitweb.ps.run Git - chirp/commitdiff
add ability to specify tag type to html_form
authorpatrick-scho <patrick.schoenberger@posteo.de>
Tue, 8 Apr 2025 18:54:10 +0000 (20:54 +0200)
committerpatrick-scho <patrick.schoenberger@posteo.de>
Tue, 8 Apr 2025 18:54:10 +0000 (20:54 +0200)
src/main.zig

index 8cabda6e31c9ed010a599d71f820f5cbbe04b7be..164606f245754a94d5998a779833f42b3d715783 100644 (file)
@@ -509,10 +509,16 @@ fn html_form(res: *http.Response, action: []const u8, inputs: anytype) !void {
 
     inline for (inputs) |input| {
         switch (@typeInfo(@TypeOf(input))) {
-            .Struct => {
-                try res.write("<input ", .{});
-                try res.write(input[0], input[1]);
-                try res.write(" />", .{});
+            .Struct => |s| {
+                if (s.fields.len == 3) {
+                    try res.write("<{s} ", .{input[0]});
+                    try res.write(input[1], input[2]);
+                    try res.write("></{s}>", .{input[0]});
+                } else {
+                    try res.write("<input ", .{});
+                    try res.write(input[0], input[1]);
+                    try res.write(" />", .{});
+                }
             },
             else => {
                 try res.write("<input ", .{});
@@ -1265,7 +1271,7 @@ const GET = struct {
             });
             try self.res.write("<br />Description: ", .{});
             try html_form(self.res, "/set_description", .{
-                .{ "type=\"text\" name=\"description\" placeholder=\"{s}\"", .{login.user.description.constSlice()} },
+                .{ "textarea", "type=\"text\" name=\"description\" placeholder=\"{s}\"", .{login.user.description.constSlice()} },
                 "type=\"submit\" value=\"Change\"",
             });
             try self.res.write("<br />Password: ", .{});