Easy forms with htmllib

A review for htmllib created by Dantom
In my last review I mentioned the htmllib library by Dantom. This library makes it easy to use HTML forms in your game and on your DMCGI website.

The library functions using a /Form datum, this datum contains various procs and vars that make your life using forms much, much easier.

First lets take a look at the form datum's variables.

/Form variables

submit (Default: "Submit")
This variable will contain the text to be displayed on the form's submit button.


reset (Default: "Reset")
This variable will contain the text to be displayed on the form's reset button.


form_url (Default: null)
This variable tells the form where to send its data when submitted (the form's action parameter).


form_sub_path (Default: null)
This variable contains any extra path information that is to be passed through the form, any text in this variable will be appended to the end of the form_url.


form_title (Default: null)
This variable contains any text you wish to pass to the 'title' parameter of your form.


form_window (Default: null)
If you have any extra browse() data you wish to pass this is how you do it, this variable is basically the same as the second argument of browse().


form_reusable (Default: null)
When set this variable will allow the user to submit the same form more than once, otherwise the form will expire and cannot be sent again.


form_cgi_mode (Default: null)
This variable tells the form whether it should be processed by client.CGI or not. This is automatically set when used in CGI mode.


form_method (Default: "get")
This variable sets the 'method' parameter of your form, the most common values are 'get' and 'post'. When using forms in Dream Seeker the method MUST be 'get' otherwise the form won't submit.


form_extra (Default: null)
This variable contains any text you wish to include into the form tag of your page. Useful for things like javascript calls and parameter settings.

The procs and how to use them

DisplayForm(mob)
Calling this proc with a mob argument will cause your form to be displayed to that mob.
var/Form/my_form/frm = new()
frm.DisplayForm(usr)



SubmitForm(href,mob)
Calling this function will force the Form datum to submit its data with. The 'href' parameter contains any extra data you want to pass through.
var/Form/my_form/frm = new()
frm.SubmitForm(null,usr)



GetSelfUrl(params,mob)
Calling this will return a friendly URL with all of your form parameters intact. (eg: http://myurl.com/mypage.dmb?form=/Form/ my_form&param=somevalue)


Initialize()
This proc is called when DisplayForm() is called, it is most useful for detecting when a certain form has been loaded.
Form
    my_form
        Initialize()
            world << "My form has been displayed!"



ProcessForm()
This proc is called when the form is finished processing. Useful for detecting when data has been successfully passed.
Form
    my_form
        ProcessForm()
            world << "My form has finished processing!"



HtmlLayout()
This proc is used to determine the HTML layout of the form.
Form
    my_form
        var/some_input
        HtmlLayout()
            return {"
            Please submit this value: [some_input]<br>
            [submit] [reset]"}

This example shows how to display an input box with your own text, as well as the submit and reset buttons.

Input types

As anyone who's ever used a HTML form before knows, there are many input types, not just text fields. This section will explain how to make use of the _interface setting for form variables.

Form
    my_form
        var
            text_input
            password_input
            password_input_interface = PASSWORD

Notice how I used the variable password_input_interface, this tells the system to check for a variable called password_input and change the input type of it to 'password'. This works for many different types of inputs.

Here is a list of all of the valid _interface types avaliable:

TEXT -- This is the default value, a simple text input.

PASSWORD -- A masked input for passwords.

TEXTAREA -- A multi-line text input, you can also set the _size of a variable to use this type.

var
    big_input
    big_input_size = "10x10"

This will make big_input a 10x10 textarea.

SELECT -- A simple single selection input. Any variable with _values will be set to this type.

var
    select_input
    select_input_values = list("One","Two","Three")

This will create a selection box with the three values included.

MULTI_SELECT -- This is the same as SELECT except it allows the user to select more than a single item.

CHECKBOX -- This creates a checkbox. When checked the variable will be true (1), if not it'll be false (null/0)

CHECKLIST -- This allows you to group checkboxes together so that their values are passed back as a _values list.

var
    checklist_input
    checklist_input_interface = CHECKLIST
    checklist_input_values = ("One","Two","Three")
ProcessForm()
    for(var/V in checklist_input_values)
        world << "[V] = [checklist_input_values[V]]"

This will output something similar to 'One = 1' 'Two = 0' and so on, depending on the checked value of the boxes in the list.

RADIO -- This creates a radio box, this interface isn't meant to be used on its own, a few variable control types are included to allow for its use.

var
    radio_input
    radio_input_interface = RADIO
    radio_input_1 = "One"
    radio_input_2 = "Two"
    radio_input_3 = "Three"

This will create three radio boxes in the same group, only one of the three can be selected at any time.

RADIO_LIST -- This works exactly like CHECKLIST except with radio inputs.

HIDDEN -- This allows you to make a hidden form element, this element won't be displayed on the form.

BUTTON -- This allows you to create a custom button. To interact you simply define a proc like varClick().

var
    button_input = "My Button"
    button_input_interface = BUTTON
proc
    button_inputClick()
        usr << "You clicked the button!"


PROMPT -- This works just like BUTTON except the return value of whatever you prompt the user for (file, icon, whatever) is returned by the Click() call instead of it just being called.

PROMPT_FOR_(SOUND/ICON/FILE) -- The same as PROMPT except all of the dialog input is handled for you.

SUB_FORM -- This allows you to include another /Form datum to be processed along with the parent form.

var
    sub_form = /Form/other_form
    sub_form_interface = SUB_FORM


Special variable amendments
As I noted in the previous section there are special amendments to variables you can use such as _interface and _size. This section will go over the ones I haven't mentioned yet.

_maxlen When used on a text input this will control the maximum length the user can input into said control.

_validate This controls whether variables using the _values system will validate their values before processing and return an error if a value is considered incorrect. It is on by default.

_hidden This works a lot like the HIDDEN interface except that variables with _hidden are automatically placed even if you override HtmlLayout().

_wrap This controls the wrapping behavior of the TEXTAREA input control, it has three possible values. NO_WRAP for no wrapping, SOFT_WRAP for simple wrapping with no newlines, and HARD_WRAP for simple wrapping with newlines.



More information about the usage and special tricks of the htmllib can be found inside of the library's documentation. And as always the DMCGI Guild is always happy to answer questions and help you out.

Posted by Nadrew on Tuesday, August 18, 2009 09:54PM - 0 comments / Members say: yea +4, nay -1

« Websites with DM · MySQL and BYOND »

Login to post a comment.

 

 

Programming Help

Get Started - A quick overview of the tools available for learning to program in BYOND.

DM Guide - This is the first place you should look if you're new to BYOND's language DM. Some people call this the "blue book".

ZBT parts 1, 2, & 3 - Zilal's excellent tutorial series, teaching you the basics of how to get started writing games in BYOND.

Your First World and Step BYOND - Sample games that you can study to help you learn.

DM Reference - Handy for novice users and advanced programmers alike, this documents everything you need to know about the DM language.

Skin Reference - If you want to give your game a custom interface, this tells you what you can do with "skins" and how to work with them.

BYOND Resources - Demos and libraries you can download to help you with your creation.

Publishing Games

Publishing Games - A guide for putting your creations on the BYOND hub to share with others.

Recording Videos - If you want to find out how to make a video of your game and put it on YouTube or another site, this can get you started.

Keywords