Add ext/web forms (design §5.5): fields, validate, submit, GET|POST /_form.

Also fix static links (URLs with dots) being misread as db fields.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-11 17:55:29 +08:00
1 parent 9599303c4c
commit ee019fb1c2
13 files changed
+890 -46

No files matched your search

@@ -5,5 +5,6 @@
| 属性 | 值 | 样式 |
|------|-----|------|
| Side | / | |
| Docs | https://github.com | |
**`side`**
+70
View File
@@ -0,0 +1,70 @@
---
title: web form smoke
description: Offline form fields / validate / submit (no listen).
> ext/web/web.mq.md
> web-fixtures/db/articles.mq.md as articles
> lib/json.mq.md
---
# main
*`store` = > web.db url="sqlite:web-fixtures/data/form-smoke.db" *
*`schema` = > articles.schema *
> `store`.init name=articles fields=`schema`
`fields` =
| 字段 | 标签 | 类型 | 必填 | 默认 |
|------|------|------|------|------|
| title | Title | text | true | |
| body | Body | textarea | false | |
`rules` =
| 字段 | 规则 | 消息 |
|------|------|------|
| title | required | Title is required |
| title | max:120 | Title is too long |
*`f` = > web.form table=articles action=insert *
*`f` = > `f`.fields fields=`fields` *
*`f` = > `f`.rules rules=`rules` *
`bad` =
| title | body |
|-------|------|
| | hello |
*`v` = > `f`.validate data=`bad` *
*`ok` = > json.get value=`v` key=ok *
1. `ok`
> print text=validate-should-fail
2. *
> print text=validate-ok
`good` =
| title | body |
|-------|------|
| From form | Body via submit |
*`sub` = > `f`.submit data=`good` db=`store` *
*`sok` = > json.get value=`sub` key=ok *
1. `sok`
> print text=submit-ok
2. *
> print text=submit-fail
*`rows` = > `store`.select table=articles limit=10 *
*`n` = > len value=`rows` *
1. `n` >= 1
> print text=db-ok
2. *
> print text=db-fail
*`html` = > `f`.render id=article *
1. `html`
> print text=render-ok
2. *
> print text=render-fail
+6
View File
@@ -54,6 +54,12 @@ description: Offline assemble + render markers (no listen).
2. *
> print text=compose-nav-fail
*`side` = > json.get value=`page` key=sidebar *
1. `side`
> print text=compose-side-ok
2. *
> print text=compose-side-fail
*`css` = > json.get value=`page` key=styles_css *
1. `css`
> print text=styles-ok
+18
View File
@@ -1234,12 +1234,30 @@ fn ext_web_smoke() {
"tests/ext/web-smoke.mq.md",
"render-ok
compose-nav-ok
compose-side-ok
styles-ok
compose-ok
db-ok",
);
}
#[test]
fn ext_web_form_smoke() {
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_web"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build web plugin");
assert!(status.success(), "failed to build marqdo_plugin_web");
assert_out(
"tests/ext/web-form-smoke.mq.md",
"validate-ok
submit-ok
db-ok
render-ok",
);
}
#[test]
fn ext_agent_framework_smoke() {
let status = Command::new("cargo")