Using HTML Form Submit - How to Get DHTMLX Values?

If a HTML form submit is used as is shown in the documentation here --> docs.dhtmlx.com/form__server_side.html

How are the values of the DHTMLX items accessed by the script that is called as the form action?

Thanks

Hello
Try method gerFormData()

Thanks, I"ll try getFormData(). How would it be accessed if the form action is a python script?

Method getFormData() works on client side. Python script is server side. There are different parts of application.

The documentation uses action=“php/save_form.php”. Instead, if a python script is the form action, is there a way for the python script to have access to the DHTMLX form data…i.e know which radio button was checked or what values the user entered in the input field.

In case others run into this same issue, the DHTMLX form values can be accessed using Python cgi.FieldStorage().

Hi

that’s correct, you need to read post data with python on server side, but form will send it automatically, no needs to call getFormData().

assuming you have the following form on client (index.html)

// declare form struct var formData = [ {type: "input", name: "login", label: "Login", value: "my_login"}, {type: "password", name: "pwd", label: "Password", value: "my_pwd"}, {type: "button", value: "Save", name: "save"} ]; // init form var myForm = new dhtmlXForm("parentObj", formData); // attach some callbacks myForm.attachEvent("onClick", function(name){ if (name == "save") { myForm.send("server.py", function(){ // callback after response received }); } });

then on server side in 1.py you need something like the following:

data = cgi.FieldStorage(); if data.getvalue("login") == "my_login" and data.getvalue("pwd") == "my_pwd": print ("{status: true}"); else: print ("{status: false}");

you can find complete code attached, do not forget to change paths to dhtmlx.js/css in section in index.html and path to python in 1.py
45.zip (1.13 KB)

Will form automatically send data (for example the file name) for an uploader as well?

It will send all data it has but you still need to call form.send()

Andrei,

I made a few modifcations to your example and attached it in a zip. I don’t use form.send. Instead I use the HTML form submit. When the ‘Save’ button is pressed, it will take you to a page that prints out the form values using python cgi.FieldStorage(). The form values include the radio button (if selected), the password and login values but never the uploader data. How do I get the uploader data?

For example, when the radio button is clicked, I will see something like this when the form data is printed:
FieldStorage(None, None, [MiniFieldStorage(‘fileTypeRadio’, ‘radio’), MiniFieldStorage(‘login’, ‘my_login’), MiniFieldStorage(‘pwd’, ‘my_pwd’)])

I never see the uploader data in the form data.
45b.zip (2.02 KB)

Hi

when uploaded inited inside a form, getFormData() used by send() also retrieve information from uploader regarding uploaded files and send them to server.

you can fine description here and then test in condole.
docs.dhtmlx.com/3.6/doku.php?id= … rm_getdata

so when using real html form, you need to add data manualy to form. just update your code a bit:

myForm.attachEvent("onButtonClick", function(name){ if (name == "save") { // create fields for uploader before form submit var a = "uploadFile"; // uploader name var data = myForm.getFormData(); var count = data[a+"_count"]; // count of uploaded files var i = document.createElement("INPUT"); i.type = "hidden"; i.name = a+"_count"; i.value = count; document.getElementById("myForm").parentNode.appendChild(i); for (var q=0; q<count; q++) { var n = [a+"_r_"+String(q), a+"_s_"+String(q)]; // [realName, serverName] for (var w=0; w<n.length; w++) { var i = document.createElement("INPUT"); i.type = "hidden"; i.name = n[w]; i.value = data[n[w]]; document.getElementById("myForm").parentNode.appendChild(i); } } document.forms[0].submit(); } });

then it will send data regarding uploded files like in getData() description above.

Thanks, I have it working now.