Form inputs

PSL supports various types of user inputs. One can easily display a form in the UI by a simple specification in the PSL file and take user inputs. In PSL, forms closely follow Mozilla Developer Network specifications.

Example

[ask.name]
description = Please enter you name:

; Taking form input
; Forms support markdown in descriptions. Labels could use any of the supported `display_option`
[ask.user_info]
input_data_type = form
description = ### Please fill this form:
form_data =
    [
        {
            "name": "alias",
            "field_type": "textarea",
            "input_type": "str",
            "description": "Enter the alias that you would like to use",
            "type_params": {
            "maxlength": 30,
            "placeholder": "{{input.name}}"
            }
        },
        {
            "name": "age",
            "field_type": "number",
            "input_type": "int",
            "description": "{{input.name}}, you need to enter your age now! 🤯",
            "type_params": {
            "min": 0,
            "max": 120,
            "step": 1
            }
        },
        {
            "name": "temperature",
            "field_type": "number",
            "input_type": "float",
            "description": "Enter the temperature",
            "type_params": {
            "min": -273.15,
            "max": 500.0,
            "step": 0.1
            }
        },
        {
            "name": "is_adult",
            "field_type": "checkbox",
            "input_type": "bool",
            "description": "Are you an adult?",
            "type_params": {
            "options": {
                "label": "Yes",
                "value": "{{input.name}}",
                "display_option": "text"
            }
            }
        },
        {
            "name": "favourite_color",
            "field_type": "select",
            "input_type": "str",
            "description": "Select your favourite colour",
            "type_params": {
            "options": [
                {
                "label": "Red",
                "value": "Red",
                "display_option": "text"
                },
                {
                "label": "Blue",
                "value": "Blue",
                "display_option": "text"
                }
            ]
            }
        }
    ]

In subsequent prompts, you can access specific info provided by the user in the form via: input.user_info.<field_name>.

For example, alias can be access via input.user_info.alias and favourite_color can be accessed via input.user_info.favorite_color[0](for fields of type select, the output is stored as a list).

[display]
text = Hey {{input.user_info.alias}}! 
    My favorite color is also {{input.user_info.favorite_color[0]}}!!

Last updated