Dashboard template: HTML form output without POST method

I have a html form in dashboard template.
iam trying to get payload containing form values without POST method.

POST method works fine.

i want form values in an array or an object format upon submitting the form. but dont want the POST method which will take it to different URL. On submitting form i want to remain in same page but i should get payload.

if anyone can guide with an example it would be good.

Thanks in advance

If you set the response code to 304 - it should tell the browser that the page is not modified and so it should not move away - https://www.restapitutorial.com/httpstatuscodes.html
This may not be what you really want - as you usually expect to get some feedback... but...

1 Like

I would use JavaScript to form a JSON packet or a GET request with the information and submit it to a handler on the webserver.

In node-red you can send an http request to an http input node and handle the request and response in a function.

you can create a script in the webpage that will take the form elements and put them together into a get request without using the form. This won't navigate way from the page unless you want it to.

For example, this is how I send stuff to my MQTT broker from various places on my network that don't have MQTT functionality built in. I use this mostly from Tasker on my phone. I don't like any of the Tasker MQTT clients. So I just make Tasker send a get request to node-red.

Anything can send an http GET to my node-red server that looks like this.

http://192.168.0.18:1880/mqttin?t=<topic>&v=<value to be set>

Anything that can make an http get request can do it.

[
    {
        "id": "7cc5a391.4e129c",
        "type": "http in",
        "z": "69aac232.e405ec",
        "name": "mqttservice",
        "url": "/mqttin",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 110,
        "y": 40,
        "wires": [
            [
                "92a4d05f.790f68"
            ]
        ]
    },
    {
        "id": "d865d6ab.68c738",
        "type": "mqtt out",
        "z": "69aac232.e405ec",
        "name": "Send package to MQTT server",
        "topic": "",
        "qos": "",
        "retain": "",
        "broker": "5e8886da.2dbd9",
        "x": 670,
        "y": 40,
        "wires": []
    },
    {
        "id": "ff83b65e.00f328",
        "type": "http response",
        "z": "69aac232.e405ec",
        "name": "HTTP response to request",
        "statusCode": "",
        "headers": {},
        "x": 660,
        "y": 80,
        "wires": []
    },
    {
        "id": "92a4d05f.790f68",
        "type": "function",
        "z": "69aac232.e405ec",
        "name": "Convert from URL GET to msg object",
        "func": "msg.topic = msg.payload.t;\nmsg.payload = msg.payload.v;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 370,
        "y": 40,
        "wires": [
            [
                "d865d6ab.68c738",
                "ff83b65e.00f328"
            ]
        ]
    },
    {
        "id": "5e8886da.2dbd9",
        "type": "mqtt-broker",
        "z": "",
        "name": "localMQTT",
        "broker": "192.168.0.18",
        "port": "1883",
        "clientid": "NR",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

There are many assorted ways to accomplish this in javascript.

Here's where you can start.

1 Like

thanks this worked

Thanks will try to handle things within javascript for my future projects , thanks for this information.

Currently used response 304 for the solution