bengillies.net

a blog by Ben Gillies

POSTing to TiddlyWeb

Following on with my current theme of making TiddlyWeb easier to use, especially without Javascript, I thought I'd introduce another little plugin that I've written. To sum it up in a sentence, it adds POST support to TiddlyWeb.

What this means in practise, is that you can put an HTML form in your page (TiddlyWebPages is a good place to put it), and when somebody clicks submit, the data they entered is POSTed to TiddlyWeb, which then stores it, all with no JavaScript whatsoever. Sounds simple right? Well yes, that's kind of the point.

To use it properly, you can POST to the following urls:

  • /bags/<bag_name>/tiddlers/<tiddler_name>
  • /recipes/<recipe_name>/tiddlers/<tiddler_name>

in the same way that you can PUT to them in normal TiddlyWeb. However, this also lets you POST direct to the bag (or recipe), allowing users to specify their own title right there in the input box. To do this, you can post to:

  • /bags/<bag_name>/tiddlers
  • /recipes/<recipe_name>/tiddlers

and just include a "title" field in your HTML form. Sometimes though, the title doesn't matter (my comments section is a good example of this), so if you don't include one, TiddlyWeb will now generate a random title for you, saving you the bother.

Fields and Values


Essentially, you could POST any set of values you like to the above URLs, and they'd get put in the right bag as tiddlers, but some names are reserved for specific tiddler attributes. They are as follows:

  • Title - this specifies the tiddler title
  • Text - this specifies the text (or content) of the tiddler
  • tags - this specifies the tags that you want the tiddler to have (specify these as a TiddlyWiki style space/double square bracket delimited list)

Other values will simply be set as tiddler fields.

Binary Files



There is one exception to this though - binary files. If you include a file input box and give it a name of "file", then TiddlyWeb will use that instead, and put that file into the correct bag (or recipe), as a tiddler. You can then both navigate to and view it in the usual way.

Example



The following would be a simple example of how to use this plugin. It assumes that the plugin has been installed already (ie - added to tiddlywebconfig.py)

<form method="POST" action="/bags/foo/tiddlers">
    <input type="text" name="title" value="Insert title here" /><br>
    <textarea rows="5" cols="40" name="text">Insert text here</textarea><br>
    <input type="tags" name="tags" value="tags" /><br>
    <input type="submit" value="Send to TiddlyWeb" />
</form>

--- or for binary files (like images) ---

<form method="POST" action="/bags/foo/tiddlers" enctype="multipart/form-data">
    <input type="file" name="file" /><br>
    <input type="submit" value="Send to TiddlyWeb" />
</form>


Its that simple. If you want this plugin, its on GitHub at http://github.com/bengillies/TiddlyWeb-Plugins/tree/master/form/

You can test it out by leaving me a comment. :)

Comments

name:
comment:
Hi,
is it possible to post a binary file and give it a tag also?
by Eduard Wagner