Skip to content

Instantly share code, notes, and snippets.

@cocoa1231
Created August 31, 2026 22:55
Show Gist options
  • Select an option

  • Save cocoa1231/3f84155f2ec9b3989f8dcd79c7b7ec83 to your computer and use it in GitHub Desktop.

Select an option

Save cocoa1231/3f84155f2ec9b3989f8dcd79c7b7ec83 to your computer and use it in GitHub Desktop.
minimal working example of lustre forms
import lustre
import gleam/io
import gleam/list
import lustre/attribute
import lustre/element.{type Element}
import lustre/element/html
import lustre/event
type Model =
Int
fn init(_) {
0
}
type Message {
UserClickedSubmit(formdata: List(#(String, String)))
}
fn update(m: Model, message: Message) -> Model {
case message {
UserClickedSubmit(data) -> {
data
|> list.map(fn(field) {
let #(name, value) = field
io.println("field name: " <> name)
io.println("filed value: " <> value)
})
m
}
}
}
fn view(_model: Model) -> Element(Message) {
html.form([event.on_submit(UserClickedSubmit)], [
html.input([attribute.type_("file"), attribute.name("filepath")]),
html.input([attribute.type_("submit")])
])
}
pub fn main() -> Nil {
let app = lustre.simple(init, update, view)
let assert Ok(_) = lustre.start(app, "#app", Nil)
Nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment