Helma logo
helma.org » Home > docs > tutorial > Handling User Input

Handling User Input

To enter data into Helma from a browser we first create an adequate layout for an HTML form:

apps/addressbook/HopObject/edit.skin:

<form action="edit" method="post">
First Name: <input type="text" name="firstname" 
    value="<% this.firstname encoding="form" %>" /><br />
Last Name: <input type="text" name="lastname" 
    value="<% this.lastname encoding="form" %>" /><br />
e-mail: <input type="text" name="email" 
    value="<% this.email encoding="form" %>" />
<p />
<input type="submit" name="submit" value=" Save " />
</form>
Save this skin as edit.skin but this time in the HopObject directory (we will reveal the reason for this later).

The corresponding action edit.hac looks like this – it needs to be saved in the Person directory:

apps/addressbook/Person/edit.hac:
res.data.title = "Edit Helma Address Book Entry";
res.data.body = this.renderSkinAsString("edit");
renderSkin("html");
Now the edit links from the main resource of our address book application should work and you should see the HTML form containing the chosen HopObject's data.

Screenshot of Addressbook application

The edit.hac / edit.skin combo works analogously to main.hac and link.skin in the previous sections. So nothing really new here except the encoding parameters in the skin markup.

They avoid HTML markup entered in the database from messing up the HTML layout. Each value returned from the macro handler is encoded like it was wrapped into a encodeForm() function.

Although the Save button already works, the data remains yet unchanged. The necessary code has to be added before the first line of edit.hac:
if (req.data.submit) {
  this.firstname = req.data.firstname;
  this.lastname = req.data.lastname;
  this.email = req.data.email;
  this.modifytime = new Date();
  res.redirect(root.href());
}
Try out to change some values and click Save afterwards – you should notice the changes immediately in the list view.


Up: Tutorial
Previous: Custom Macros Next: Creating A HopObject

... comment


Page last modified on 2005-10-17 21:30 by czv