Toggling the Skip Empty Fields Feature
Before we can toggle the empty fields feature, we need to
apply the Dreamweaver update server behavior and Pure ASP Upload. Let's go ahead
and do that now. But don't save the page yet.
Switch to code view and look at the Dreamweaver update
server behavior code you'll notice that it's
using the generic Request() Collection and the Request.Form() collection. Now save the page and as you do watch the code changes. You just saw the Pure ASP
Upload modify the Dreamweaver server update server behavior for uploads. You'll notice
that the generic Request() and Request.Form collections have been replaced with UploadFormRequest(). What you've just seen usually goes on
behind-the-scenes. If you were paying close attention you may have noticed that
the image field parameter code has also changed.
Tip: The generic Request() and the
Request.Form() collections cannot be called after calling a binary upload.
The DMXzone Pure ASP Upload extension has implemented the MM_IIF for the skip empty fields feature. The MM_IIF enough returns one of two values
true or false. A false value means the requested field is null or empty. A true
value indicates that the requested field is not empty. If the MM_IIF returns
false, the hidden field upload_org_image_field created by the Pure ASP
Upload extension which contains the original image field value is substituted
for the upload form field, thus skipping the empty field. This is the parameter
we're going to use to toggle the skip empty fields feature. We're going to do
this by creating two parameters: one which skips the empty field using the
MM_IIF and one that does not skip the empty field. Then we are placing them in
an if… then… else statement and using the Delete Image? checkbox to
toggle the feature and set the database image field value to null or skip the
empty field when we wish.
Tip: You'll find the MM_IIF implementation in
the code block immediately above the Dreamweaver update server behaviour.
Now that we know what we are going to do, let's get to it.
The modified Dreamweaver update server behavior appears in the code block
below. In this case the name of my image field is named Link_Image. You will
notice I have added a blank space and a comment before and after our If… Then…
Else… statement. Notice I've used the UploadFormRequest collection created by
Pure ASP Upload to request the value of the Delete Image? checkbox. If the
value is anything other than null, the code to reset the image field value to
null is activated. Notice that if the user checks the Delete Image? checkbox
and uploads a new image, the page still works properly and the image name value
is updated in the database.
If (CStr(UploadFormRequest("MM_update")) = "UpdateForm") Then
If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_datasource_STRING
MM_editCmd.CommandText = "UPDATE Links SET Link_Title = ?,
Link_URL = ?, Link_Image = ?, Link_Description = ? WHERE Link_ID = ?"
MM_editCmd.Prepared = true
203, 1, 536870910, UploadFormRequest("Link_Title")) ' adLongVarWChar
203, 1, 536870910, UploadFormRequest("Link_URL")) ' adLongVarWChar
'Toggle skip empty field behavior to remove existing image
If CStr(UploadFormRequest("Delete_Image")) <> "" Then
203, 1, 536870910, UploadFormRequest("Link_Image")) ' adLongVarWChar
203, 1, 536870910, MM_IIF(UploadFormRequest("Link_Image"), UploadFormRequest("Link_Image"),
UploadFormRequest("upload_org_Link_Image"))) ' adLongVarWChar
203, 1, 536870910, UploadFormRequest("Link_Description")) ' adLongVarWChar
5, 1, -1, MM_IIF(UploadFormRequest("MM_recordId"), UploadFormRequest("MM_recordId"),
null)) ' adDouble
The line of code after the Then uses the Dreamweaver
generated parameter code modified for upload. It does not use the MM_IIF
implementation and does not skip the empty field. The line of code after the Else uses the parameter as modified by the pure ASP upload extension with the MM implementation
and skips a beat fields, instead using the value from the hidden field
upload_org_Link_Image, which as you recall holds the value of the original
image. Now all we have to do is close the If… Then… Else I statement with the
final End If.
Tip: The parameters both have the same name:
param3 in the example. This is because only one parameter is used in the SQL
statement depending upon the condition of the Delete Image? checkbox.
Now that we have successfully toggled the skip empty fields
feature. It's time to set up the image delete.