When the solution matters

Tips...

Registration Documentation Knowledgebase Seminars / Training Technical Support Partner Central

WebForms

In the previous step, we saw how 4D will assign HTML form item values to like-named 4D variables. That is a nice feature, and it has many uses. However, what happens when you don't know ahead of time what data the form will be sending to 4D? To retrieve that data, you will need to use another 4D command: GET WEB FORM VARIABLES .

Return again to 4D's Design environment, bring up the Explorer, and create a new Project Method. You should name this method "WSC_FormHandler2". Type (or copy-and-paste) the following code into it:

ARRAY TEXT($atNames;0)
ARRAY TEXT($atValues;0)

GET WEB FORM VARIABLES($atNames;$atValues)

C_TEXT($tReply)
C_LONGINT($iIdx)

$tReply:="Data Received: <P>"

For ($iIdx;1;Size of array($atValues))
$tReply:=$tReply+"<b>"+$atNames{$iIdx}+": </b>"+$atValues{$iIdx}+"<BR>"
End for

SEND HTML TEXT($tReply)

screenshot

Your WSC_FormHandler2 method should look like the one in the picture above. Go to the Method menu and choose Method Properties, then select the Available through 4DACTION option in the properties dialog.

Press the OK button and then close the WSC_FormHandler method before proceeding.

Next, return to your text editor. Open up the "index.html" file that you used earlier and replace everything in the file with the following:

<html>
<head>
<title>4D Web Forms</title>
</head>
<body>
<form name="TestForm" method="POST" action="/4DACTION/WSC_FormHandler2">
<h2>Tell me some things about yourself:</h2>
<p>
Full Name: <input type="text" name="FullName" value="">
<br>
Favorite Color: <input type="text" name="EyeColor" value="">
<br>
<input type="submit" name="submitbutton" value="submit">
</p>
</form>
</body>
</html>

Save this file - again, make sure it is in your WebFolder.

Return to your web browser, and once again type 127.0.0.1 in the address field:

screenshot

Your web browser should look like the one in the picture above. Enter some information into the fields. Perhaps you could supply the name "John Doe" and a favorite color of "Blue". Hit the submit button. If everything worked, your web browser should look something like this:

screenshot

What's interesting about the WSC_FormHandler2 method is that it will work for an unlimited number of HTML form inputs. Go ahead and edit the index.html file, add some more form fields, and re-submit the form to 4D. The WSC_FormHandler2 method should be able to handle anything you throw at it.

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


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