Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%
- ' Check if the form is submitted
- If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
- ' Retrieve the signature data from the request
- Dim signatureData
- signatureData = Request.Form("signatureData")
- ' Convert the data URL to a blob
- Dim signatureBlob
- 'signatureBlob = DataURIToBlob(signatureData)
- ' Connect to the SQL database
- Dim conn
- Set conn = Server.CreateObject("ADODB.Connection")
- conn.Open "Driver={SQL Server}; Server=ctech-gla-sql03; Database=SIC30_CTS_LIVE; UID=webuser; PWD=webuser; Option=4"
- ' Prepare an SQL INSERT statement to save the blob
- Dim sql
- sql = "UPDATE call_events SET ce_technicians_signature_image = '@SignatureData' WHERE ce_Id = '56729908'"
- ' Create a parameterized command and set the blob value
- Dim cmd
- Set cmd = Server.CreateObject("ADODB.Command")
- cmd.ActiveConnection = conn
- cmd.CommandText = sql
- ' Create a parameter and assign the blob value
- Dim param
- 'Set param = cmd.CreateParameter("@SignatureBlob", 205, 1, LenB(signatureBlob), signatureBlob)
- Set param = cmd.CreateParameter("@SignatureBlob", 205, 1, LenB(signatureData), signatureData)
- cmd.Parameters.Append param
- ' Execute the INSERT statement
- cmd.Execute
- 'response.write(sql)
- ' Cleanup
- Set param = Nothing
- Set cmd = Nothing
- conn.Close
- Set conn = Nothing
- ' Display a success message
- Response.Write "Signature successfully saved."
- End If
- ' Function to convert data URI to blob
- Function DataURIToBlob(dataURI)
- Dim byteString, base64Data, hexString, bytes
- byteString = Mid(dataURI, InStr(dataURI, ",") + 1)
- base64Data = Base64Decode(byteString)
- bytes = (LenB(base64Data) \ 2)
- Dim binaryData
- ReDim binaryData(bytes - 1)
- Dim i
- For i = 1 To bytes
- binaryData(i - 1) = AscB(MidB(base64Data, i, 1))
- Next
- ' Convert binary data to a hexadecimal string
- hexString = ""
- For i = 1 To bytes
- hexString = hexString & Right("0" & Hex(binaryData(i - 1)), 2)
- Next
- DataURIToBlob = hexString
- End Function
- ' Function to decode base64 string
- Function Base64Decode(base64)
- Dim dm, padding, unpaddedLength, numPaddings, i
- Set dm = CreateObject("Microsoft.XMLDOM")
- padding = 0
- unpaddedLength = Len(base64)
- If Right(base64, 1) = "=" Then
- padding = 1
- If Right(base64, 2) = "==" Then
- padding = 2
- End If
- unpaddedLength = unpaddedLength * 3 \ 4 - padding
- End If
- numPaddings = unpaddedLength Mod 3
- base64 = Replace(base64, "=", "")
- base64 = Replace(base64, "+", "-")
- base64 = Replace(base64, "/", "_")
- base64 = Replace(base64, vbNewLine, "")
- For i = 1 To numPaddings
- base64 = base64 & "="
- Next
- Base64Decode = dm.createTextNode(base64).NodeTypedValue
- End Function
- %>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Signature Capture Form</title>
- <script src="https://unpkg.com/signature_pad"></script>
- <script>
- // Initialize the signature pad
- var signaturePad;
- window.onload = function() {
- var canvas = document.getElementById('signatureCanvas');
- signaturePad = new SignaturePad(canvas);
- };
- // Function to handle form submission
- function handleSubmit(event) {
- event.preventDefault(); // Prevent form submission
- // Get the signature as a data URL
- var signatureDataUrl = signaturePad.toDataURL();
- // Set the signature data as a hidden form field
- document.getElementById('signatureData').value = signatureDataUrl;
- // Submit the form
- document.getElementById('signatureForm').submit();
- }
- </script>
- <style>
- #signatureCanvas {
- border: 1px solid #000;
- }
- </style>
- </head>
- <body>
- <h1>Signature Capture Form</h1>
- <form id="signatureForm" method="post" action="">
- <label for="signatureCanvas">Please sign below:</label><br>
- <canvas id="signatureCanvas" width="400" height="200"></canvas><br>
- <input type="hidden" id="signatureData" name="signatureData" value="">
- <button type="submit" onclick="handleSubmit(event)">Submit</button>
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment