Often you will want to capture data from forms and perform an action, such as sending mail after submission of a contact form. In Weceem this is achieved by writing some Groovy code that you store in the content repository. This happens dynamically and you don't need to redeploy your Weceem application or restart it.
Two content types work together in Weceem to enable you to write arbitrary server-side code. The Scripted Action node type is used to receive requests, and delegates the work to a Groovy Script node.
So for example to create a Contact form that sends mail to a known address, you could implement it like this:
def args = [
recipients:'admin@yourserver.com',
subject:'Message from website visitor'
]
try {
sendMail {
to args.recipients
if (args.ccRecipients) {
cc args.ccRecipients
}
subject args.subject
from params.senderAddress
body params.message
}
redirect(uri:params.success)
} catch (Exception e) {
log.error "Can't send mail", e
redirect(uri:params.error)
}With the above example, the HTML form needs to supply fields "senderAddress" and "message". It will redirect the user to the value of the "success" parameter, which will usually be a URI in your content repository created using the wcm:createLink tag.
Note that you can write any Groovy code you like in the Groovy Script node. The possibilities are endless - you can call out to external web services, perform calculations, render complex results in alternative formats (e.g. JSON).
As ever, with great power comes great responsibility. You can easily degrade the performance of your server by writing inefficient code in a Groovy Script that is executed frequently.
It is strongly recommended that you limit the users that can create Groovy Scripts using the Weceem Security Policy.