Skip to content

Code Reference

Moritz Tim W. edited this page Nov 14, 2023 · 34 revisions

Nodes

FormContainer: Container

Manages form submission and is intended to contain the form elements.

Properties

submit_button: Submit

Calls the submit() function when pressed.

protocol: Protocol

Handles the submission of the form.

Methods

submit

Submits the form data to the protocol if the data is valid.

generate_fields_dict

-> Dictionary
Generates a dictionary of the form data.
If a key with the same name already exists, the instance id is joined with an underscore to the key.
Example of a key with instance id: "Input_29460792527"

Parameters:
  • include_labels := false
if include_labels:
	return { { "label": ..., "input": ... }, ... }
else:
	return { input, ... }
  • subject: Node = self
    The node to generate the dictionary from.
    This is mainly used for recursion.
  • fields := {}
    The dictionary to add the fields to.
    This is mainly used for recursion.

is_input

-> bool
Returns whether the given node is an input.
Inputs are:

  • buttons except MenuButton
  • LineEdit
  • TextEdit
  • ItemList
  • Slider
  • SpinBox
  • GraphEdit

Parameters:

  • subject: Node

Submit: Button

Button that submits the form data.

This class only exists to avoid having to rename a button and to have an icon in the editor

ValidatableLineEdit: LineEdit

LineEdit with a [validator].

Properties

validator: [Validator]

Methods

_init

Assigns the style from the [validator] if it exists.

ValidatableTextEdit: TextEdit

TextEdit with a [validator].

Properties

validator: [Validator]

Methods

_init

Assigns the style from the [validator] if it exists.

FormLabel : Label

Label for input controls

Properties

input: Control

Input control to label
Must be an input according to FormContainer.is_input

input_required:= false

Input must not be empty

invalid_style: StyleBox

The style to apply to the input if invalid

valid_style: StyleBox

The style to apply to the input if valid

_valid_style: StyleBox

Internal storage for valid_style

required_hint:= "*"

String to append to label if input_required

Mode: enum

  • SEPARATE
    Display the text as the label.text
  • IN_INPUT
    Hide the label and overwrite input.placeholder_text or for lack thereof, input.text
  • HIDDEN
    Hide the label

mode:= Mode.SEPARATE

How to display the label

Methods

enter_tree

-> void
Sets the label text to the input's name if it is empty and runs necessary setters

indicate_required

-> void
Add or remove the required_hint if input_required

indicate_validity

-> bool
Change style based on validity and return validity or default if input is not validatable

validate_on_input

-> void
Indicate validity when the input node recieves a GUI input

Parameters:

default := true the default value to return if input is not validatable

has_property

-> bool
Return validity of "Subject has property_name and it is not a method"

Parameters:

subject := Object property_name := String

_on_gui_input

-> void
Indicate validity on GUI input if event is relevant and validate_on_input

Parameters:

event := InputEvent

Resources

Protocol: Resource

Handles form submission and response.

Methods

submit

-> int
Submits form data and returns HTTP status code of the response.

Parameters:

get_value

-> Variant
Finds the value of the given Node based on its type.
Throws an error if the type is unknown.
BaseButton -> button_pressed: bool
LineEdit | TextEdit -> text: String
Slider | SpinBox -> value: float
GraphEdit -> get_connection_list(): Array[Dictionary]
ItemList -> items:

Array[{
	selected = is_selected(): bool,
	text = get_item_text(): String,
	icon = get_item_icon(): Texture,
	metadata = get_item_metadata(): Variant
}]

Validator: Resource

Validates Text Input according to rules about length and content.

Properties

REGEX_LIB: Array[String]

A collection of predefined regular expression patterns.
Items correspond to the PredefinedRegex

required:= false

Input must have a value.
[min_length] will be adjusted if needed.

_prev_min_length:= 0

temporary storage of min_length used by the setter of required

min_length:= 0

Minimum length of the input.

word_range: [Boundaries]

Minimum and Maximum number of matches for \w+ allowed

whitelist: [ListFilter]

List of allowed strings.

blacklist: [ListFilter]

List of prohibited strings.

PredefinedRegex: enum

  1. NONE
  2. ALPHABETICAL
  3. NUMERICAL
  4. ALPHANUMERICAL
  5. EMAIL_ADDRESS
  6. PHONE_NUMBER

predefined := PredefinedRegex.NONE

Predefined pattern to match against.

Behavior: enum

  1. MUST_MATCH_BOTH
    Input must match both the predefined and the custom regex (if both are set)
  2. CAN_MATCH_EITHER
    Input can match either the predefined or the custom regex (if at least one is set)

behavior := Behavior.ALLOW

How predefined and custom regexes are checked against in relation to each other.

custom := ".*"

Custom Pattern to match against.

normalise := false

Normalise the case before matching.

require_single_match := false

Don't allow any more than one match.

Methods

_init

-> void
Compiles the custom regex

_on_text_changed

-> void
Validates given text and updates valid property.

Parameters:
  • new_text: String
    New content of the input

validate

-> bool
Validates given text against all rules and returns validity

Parameters:
  • subject: String
    Text to validate

Boundaries: Resource

An upper and lower bound of an integer value.

Properties

min: int

Lower bound

max: int

Upper bound

Methods

has

-> bool
Determines if the subject is within the boundaries.

Parameters:
  • subject: int

ListFilter: Resource

A filter with a blacklist or whitelist of strings

Properties

Match: enum

  1. ALL
    All elements must be present
  2. AT_LEAST_ONE
    At least one element must be present

match : Match

Match requirement

elements: Array[String]

The blacklist or whitelist

Methods

is_represented_in

-> bool
Returns wether the subject is represented in the list

Parameters:
  • subject: String

size

-> int
Returns the output of elements.size()

Protocols

FileProtocol: Protocol

Handles form submission to a JSON file.

Properties

target_dir

Directory to save responses to.

file_name_scheme

File name scheme. Available variables:

  • {hash}: Hash of the form data.
  • {id}: Number of existing files in the target directory + 1.
  • {year}: Current year.
  • {month}: Current month.
  • {day}: Current day.
  • {weekday}: Current weekday.
  • {hour}: Current hour.
  • {minute}: Current minute.
  • {second}: Current second.

Methods

submit(fields: Dictionary) -> int

Saves form data to a new file according to the file_name_scheme and returns 200.

Parameters

  • fields: Dictionary - The output of FormContainer.generate_fields_dict().

NetworkProtocol: Protocol

Handles form submission and response over the network.

Properties

host := localhost

Target hostname

port := -1

Target port -1 means "use default port"

use_host_authentication := false

Use authentication for target

host_username := ""

Username at target

host_password := ""

Password at target

host_keyfile := ""

Path to private key file

Methods

_init

-> void
Tries to set host_username based on environment var, if not already set.

HttpProtocol: NetworkProtocol

Handles form submission and response over the network using HyperText Transfer Protocol
Web export is not supported.
Based on tutorial Godot Docs > Tutorials > Networking > HTTP Client Class

Properties

encrypt := true

Use HTTPS

path := "/"

Target path

Method: enum

  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • TRACE
  • CONNECT
  • PATCH

method := Method.POST

HTTP Method

headers := {}

HTTP Headers

http := HTTPClient.new()

HTTP Client

base_url: String

{protocol}://{host}

Signals

response_received

Parameters:
  • code : int
    HTTP Status Code
  • headers : Dictionary
  • body : PackedByteArray

Methods

_init

-> void
Sets the port to 443 if encrypt is true, otherwise 80, if it is set to -1.

submit

Submits form data and returns HTTP status code of the response.
Web export is not supported.

Parameters:
  • fields: Dictionary

http_client_status_to_string

-> String
Returns a string representation of the HTTPClient.STATUS_. or "Status: {status}" if the status is not one of the following:
2. Error resolving host {host}
4. Error connecting to host {host}:{port}
8. Error in HTTP connection
9. Error in TLS handshake

Parameters:
  • status: int
    Status returned by HTTPClient.get_status()

MailProtocol: NetworkProtocol

Handles form submission and response over the network using E-Mail.

Properties

BodyFormat: enum

  • HTML
    Stylable HyperText Markup Language Form with disabled inputs
  • PLAIN_TEXT
    {key}: {value}
  • JSON
    JavaScript Object Notation

body_format := BodyFormat.HTML

css := "{addon_path}/styles/default.css"

Path to CSS file to use for styling regardless of body_format

from_name: String

Sender name

from_address: String

Sender address

to_address: String

Recipient address

subject: String

Subject line

Methods

submit

-> int
Submits form data in an E-Mail to the recipient and returns HTTP status code of the response.

Parameters:
  • fields: Dictionary

generate_body

-> String
Generates the body for the E-Mail

Parameters:
  • fields: Dictionary
    Output of FormContainer.generate_fields_dict() to populate body

type_to_string

-> String
Converts a type to a string for use in HTML form.
TYPE_STRING -> "text"
TYPE_BOOL -> "checkbox"
TYPE_INT -> "number"
TYPE_FLOAT -> "number"
TYPE_ARRAY -> "select"
TYPE_NIL -> "text"

Parameters:
  • type: int Output of typeof()

get_value

-> String
Returns the value of a node as a string for use in the E-Mail body.

Parameters:
  • subject: Node

SmtpMailProtocol: MailProtocol

Handles form submission and response over the network using Simple Mail Transfer Protocol

Properties

SecurityType: enum

  1. NONE
  2. SSL
  3. TLS

security_type := SecurityType.NONE

Security Type Adjusts the port if it is 0, 465 or 587.

use_authentication := true

Authenticate with the mail server

username: String

Username at the mail server

password: String

Password at the mail server

Methods

_init

-> void
Sets the port based on the security type if it is -1.

submit

-> int
Returns handle_smtp(generate_body(fields)).

Parameters:
  • fields: Dictionary
    Output of FormContainer.generate_fields_dict() to populate body

handle_smtp

-> int
Handles the SMTP request and returns the status code.

Parameters:
  • body: String
    E-Mail body

MailsendSmtpMailProtocol: SmtpMailProtocol

Handles form submission and response over the network using mailsend.
Mailsend must be installed.

Properties

mailsend_executable_path := "mailsend-go"

debug := false

Print debug messages

verifyCert := false

Verify the certificate in connection

log := ""

Write log messages to this file

Methods

handle_smtp

-> int
Calls mailsend with the given body and parameters based on the properties and returns the status code.

Parameters:
  • body: String
    E-Mail body
Clone this wiki locally