2

我的代码在 REPL 中运行良好,但在我的 Web 应用程序中没有获得第二个值。

例如(?vehicle=bike&vehicle=car)

我试过的

当我做

  • CL-用户> (setf |vehicle| '(a b c)
  • CL-用户> (let ((|vehicle| (multival-plist:getf-all `(:|vehicle| ,|vehicle|) :|vehicle|))) (print (alexandria:flatten (list :vehicle |vehicle|))))

这会产生所需的输出(:VEHICLE A B C)

但是当我提交表格时

<form action="/checkbox">
    <input type="checkbox" name="vehicle" value="bike"> I have a bike<br>
    <input type="checkbox" name="vehicle" value="car"> I have a car<br>
    <input type="submit" value="Submit">
</form> 

到我的路线

@route GET "/checkbox"
(lambda (&key |vehicle|)
  (let ((|vehicle| (multival-plist:getf-all `(:|vehicle| ,|vehicle|) :|vehicle|)))
    (format nil "~a" (list :vehicle (alexandria:flatten |vehicle|)))))

实际上我将结果渲染到 djula 模板,但是为了测试我使用format了。

<ul>
    {% for a in vehicle %}
        <li>{{ a }}</li>
    {% endfor %}
</ul>

结果只(VEHICLE (bike))检查了其中两个,导致

  • 自行车

我期望发生的事情

输出应该

  • 自行车

我将在我的应用程序中使用 16 个复选框,这将导致链接很长,任何建议使链接变短。

PS:我使用 Hunchentoot 服务器和 Caveman2 网络框架。

4

1 回答 1

0

在 html 中更改name=vehiclename=vehicle[],caveman2 会将其解析为值列表("bike" "car"),当两者都检查为vehicle.

于 2017-11-19T13:36:05.200 回答