pages/adp/forms.adp:
<%#-*- mode:web; fill-column:120; -*-
ns_adp_include [ns_serverpath]/app/adp.adp
namespace eval form {
variable form [ns_getform]
variable value [ns_set get $form value]
if {![string length $value]} {set value nothing}
variable action screwed
switch [ns_conn method] {
GET {set verb got}
POST {set verb posted}
default {
error "whatsupp"
ns_returnnotice 405 "Method Not Allowed"\
"The requested method is not allowed on this server: [ns_conn method]"
ns_adp_abort
}
}
}
proc ::page::content {} {
ns_adp_puts {
<article>
<p>Strategy: Depending on the HTTP method</p>
<aside>
See how it's done: <a href="show_file.adp?path=pages/adp/forms.adp">source code of this page</a>
</aside>
<ol>
<li>
Process submitted form data.
</li>
<li>Render the page, build up the form(s).</li>
</ol>
<p>How?</p>
<aside>
An <a href="https://naviserver.sourceforge.io/5/naviserver/files/ns_set.html"><code>ns_set</code></a> is a <code>dict</code> on steroids.
</aside>
<dl>
<dt><code>ns_getform</code></dt><dd>returns an <code>ns_set</code> with the form values, if any.</dd>
<dt><code>ns_conn method</code></dt><dd>returns the method used (<code>GET</code>, <code>POST</code>, …)</dd>
</dl>
<aside>
Caution! Quote whatever data you get from the user before putting it back on a web page!
</aside>
</article>
}
ns_adp_include [ns_serverpath]/tpl/adp/forms.adp
}
ns_adp_include [ns_serverpath]/tpl/site.adp
%>