I am trying to use the avatar API in a form that will post a file object to older server technology. The following demo works, and was wondering if the avatar API could be set up to do the same … where the class included in server-side code accepts a file object submitted by the form action and saves to a folder on the server
client-side
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM ACTION = "clsUpload.asp" ENCTYPE="multipart/form-data" METHOD="POST">
File Name: <INPUT TYPE=FILE NAME="avatar"><P>
<INPUT TYPE = "SUBMIT" NAME="cmdSubmit" VALUE="SUBMIT">
</FORM>
</BODY>
</HTML>
server-side
<!--#include file="freeASPUpload.asp"-->
<%
Set o = new clsUpload
If o.Exists("cmdSubmit") Then
o.FileInputName = "avatar"
o.FileFullPath = Server.MapPath(".") & "\UploadedFiles\" & o.FileNameOf("avatar")
o.Save
If o.Error = "" then
Response.Write o.FileFullPath
End if
Set o = nothing
End If
%>
I do not know how to access the file object under the avatar API…
Unless there is something better…I am trying to mimic above with the following :
Note - some pseudocode as I do not know how to access form object from avatar AP or pass form inputs as parameters to server along with the avatar (image)I
client-side dhtmlx form
<div id="container"></div>
<script>
const form = new dhx.Form("container", {
rows: [
{
name: "avatar",
type: "avatar",
size: "medium", // "small" | "medium" | "large" | number
labelWidth: 140,
label: "Avatar",
labelPosition: "top",
icon: "dxi dxi-person",
placeholder: "Add image",
updateFromResponse:true,
fieldname: "file",
accept: "image/*",
successMessage: "Success",
errorMessage: "Error",
alt: "Avatar",
target: "https://server/clsUpload.asp",
value: [] //src, etc. ?
parameters: // how to submit image AND other form inputs?
},
{
type: "input",
name: "displayname",
label: "Display Name"
},
{
name: "cmdSubmit",
type: "button", // submit ? <<< server looks for submitted objects called cmdSubmit and avatar (See example code above)
text: "Submit"
}
]
});
form.events.on("click", function(name,e){
obj = form.getItem("avatar").getProperties();
url = obj.target
params = obj.parameters
var xhttp;
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
response = this.responseText; // server path and file saved
if (response.length > 0) {
dhx.message({
text: "Form Posted",
expire: 1500,
icon: "dxi_pass dxi-check",
position: "bottom-right",
css: "dhx_message--success custom-message"
});
form.clear();
}
else {
dhx.message({
text: "Form was not posted",
expire: 1500,
icon: "dxi_fail dxi-close",
position: "bottom-right",
css: "message-fail custom-message"
});
}
}
else {}
};
xhttp.open("POST", url, true);
xhttp.send();
}
});
});
</script>