using Statum; namespace ClankerSaddle { /** * Form-reading helpers shared by the app's actions: a missing form or * field is an empty value, and empty optional fields read as null * (meaning "leave unchanged"). */ public class Forms : Object { /** The trimmed value of form field `name`, or "" when absent. */ public static string field(StatumRequest request, string name) { return request.form != null ? (request.form.get_field(name) ?? "").strip() : ""; } /** The raw (untrimmed) value of form field `name`, or "". */ public static string field_raw(StatumRequest request, string name) { return request.form != null ? (request.form.get_field(name) ?? "") : ""; } /** * The trimmed value of form field `name` as a nullable: null when * the form or field is absent or empty. */ public static string? optional(StatumRequest request, string name) { var value = field(request, name); return value.length > 0 ? value : null; } /** The integer value of form field `name`, or `fallback`. */ public static int64 integer(StatumRequest request, string name, int64 fallback) { var value = field(request, name); return value.length > 0 ? int64.parse(value) : fallback; } } }