When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Technical Support Partner Central

Room 4 Rent

Try entering some information for a reference. Then click the "Save and Add Another" button. When you do that, 4D should reply by sending the same page back to you, only this time it will look a little different:

screenshot

This page you are looking at comes from the file named "references.shtml". It uses a variety of 4D Tags: 4DIF, 4DELSE, 4DENDIF, 4DLOOP, 4DENDLOOP, and 4DVAR. This file actually contains two HTML forms. The first <form> wasn't displayed before we had supplied any References, but it is shown after you have provided at least one. Let's take a look at the first part of this page's source:

screenshot

The part you are looking at begins with a 4DIF (records in selection([References])>0). So everything between this line and the <!--4DELSE--> will appear only if the Applicant has already supplied at least one Reference. And what appears between these two tags? First, we see this:

<form name="delete_references" method="post" action="/4DACTION/WSC_FormPost/ReferenceDelete">

An HTML form is created which surrounds a <table> that displays the References the Applicant has submitted. The References are displayed using a combination of 4DLOOP and 4DVAR, embedded within that <table> tag.

Pay particular attention to this bit of the page:

<input type="checkbox" value="Yes" name="ckRefID_<!--4DVAR [References]ID-->">

As each Reference is written within the 4DLOOP, the [References]ID will be appended to "ckRefID_" so that the checkbox tags will look like this after they have been sent out by 4D's Web Server:

<input type="checkbox" value="Yes" name="ckRefID_101">

So what happens if you click the check box and then hit the "Delete Checked" button? Well, you should be able to tell that, as usual, the WSC_FormPost method will be called, and "ReferenceDelete" will be passed to it as a parameter. In turn, WSC_FormPost will execute the WSC_ReferenceDelete method. If you examine this method, it's also a bit on the big side. So let's start by examining just a small portion of it:

screenshot

What we are doing here is we are looking to find the Form Items with names beginning with "ckRefID_". The WSC_ai_FormItemIndex array will be populated with the index numbers of matching form items. It is a little difficult to describe how this works to a novice, and often times a picture is worth a thousand words.So look at this:

screenshot

This is a screen shot of the 4D Debugger as a Reference is deleted, just after the call to WSC_FormItemsMatching. The lower-right section of the window shows the WSC_at_FormItemNames and WSC_at_FormItemValues arrays expanded. Excluding element 0, you can see that there are three elements in WSC_at_FormItemNames. The first element is "ckRefID_1". And in WSC_ai_FormItemIndex, again excluding element 0, there is one element. The value of this element is 1. This means that element #1 of WSC_at_FormItemNames contains a value that begins with "ckRefID_".

So now that we know how many References were submitted for deletion, we need to carry out deleting them. That is accomplished by this portion of the WSC_ReferenceDelete method.

screenshot

We will loop through as many matches for "ckRefID_" as we have found - in this case, it's only 1. To make the code more legible, we copy the "matching element number" to the $iMatchElement variable. Then we find the name of the Form Item for that $iMatchElement. And in this case, the value of WSC_at_FormItemNames{$iMatchElement} is "ckRefID_1". This value is assigned to the $tName variable.

We find the Primary Key value we want to delete this way:

$iKeyValue:=Num(Substring($tName;$iSubLength))

Once we find the Primary Key value of the [References] record we wish to delete, we make a Query for the record:

QUERY([References];[References]ID=$iKeyValue)

Before the record is deleted, we do some standard error checking: is there a record with that Key Value? Does it belong to the correct Applicant? Do we have write access to the record, so we can delete it? If so, we finally delete the record: DELETE RECORD([References]).

We have covered a lot of material here! You may be feeling a bit overwhelmed at this point, and if you are, that's normal! Before you proceed, you might want to set a break point or two in WSC_FormPost and subsequent methods, and step through the process yourself in 4D's Debugger. Having a thorough understanding of how the "references.shtml" and associated 4D methods works will aid in your mastery of 4th Dimension's web serving capabilities.

Previous  1 2 3 4 5 6 7 8 9 10 11 12  Next Step


International | Company | Contact 4D | Site Map | Privacy Policy | © 4D UK 1995-2008 | Change font size: [A] [A] [A] | Print this page