Database Register

Script for Saving

The file you set in the database register’s value Save, will be called by Consolo when the user saves an existing or new post with the form defined in Script for Editing.

Request sent to the script by POST:

Response from the script should be given in the following format:

<?xml version="1.0" encoding="ISO-8859-1"?>
<RESPONSE>
  <RESULT>0/1</RESULT>
  <MESSAGE>Message</MESSAGE>
  <ID>Id</ID>
</RESPONSE>

Thanks to this solution, you can verify the information that is sent and alert the user about what went wrong and should be corrected.

 

Exemple

The example shows how to create a script for saving in SQL-connected ASP. If you are using another environment on your server, please translate the script to the suitable language.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- #INCLUDE VIRTUAL= '/consolo/db_opendb.asp'-->
<% If Request("password") <> "abc123" Then Response.End
tId = Request("id")
Set xmlDoc = Server.CreateObject("msxml2.DOMDocument")
xmlDoc.async = False
If xmlDoc.loadXML(Request("data")) Then
 Set xmlNodes = xmlDoc.childNodes
 aTitle = xmlDoc.getElementsByTagName("Title_VC").item(0).Text
 aText = xmlDoc.getElementsByTagName("Text_VC").item(0).Text
 aDate = xmlDoc.getElementsByTagName("Date_VC").item(0).Text
 aNewspaper = xmlDoc.getElementsByTagName("Newspaper_VC").item(0).Text

If tId = "" Then
  ' New object
  SQLstr = "INSERT INTO Presscutting_T (Title_VC, Text_VC, Date_VC, Newspaper_VC) VALUES (" & SSQn(aTitle) & SSQc(aText) & SSQc(aDate) & SSQc(aNewspaper) & ")"
  Connect.Execute(SQLstr)
  Set RS = Connect.Execute("SELECT MAX(Presscutting_ID) As New_ID FROM Arbetsliv_Presscutting_T")
  tId = RS("New_ID")
 Else
  ' Save to existing object
  SQLstr = "UPDATE Presscutting_T SET "
  SQLstr = SQLstr & "Title_VC = " & SSQn(aTitle)
  SQLstr = SQLstr & ", Text_VC = " & SSQn(aText)
  SQLstr = SQLstr & ", Date_VC = " & SSQn(aDate)
  SQLstr = SQLstr & ", Newspaper_VC = " & SSQn(aNewspaper)
  SQLstr = SQLstr & " WHERE Presscutting_ID = " & tId
  Connect.Execute(SQLstr)
 End If
%>
<RESPONSE>
  <RESULT>1</RESULT>
  <MESSAGE>Data has been saved.</MESSAGE>
  <ID><%=tId%></ID>
</RESPONSE>
<% Else %>
<RESPONSE>
  <RESULT>0</RESULT>
  <MESSAGE>Error, data could not be saved</MESSAGE>
  <ID><%=tId%></ID>
</RESPONSE>
<% End If

Function SSQn(str)
 str = Replace(str, "'", """")
 SSQn = "'" & str & "'"
End Function

Function SSQc(str)
 str = Replace(str, "'", """")
 SSQc = ", '" & str & "'"
End Function
%>