4D v16.3Binding 4D objects with HTML objects |
||
|
4D v16.3
Binding 4D objects with HTML objects
Binding 4D objects with HTML objects
4D's Web server lets you recover "posted" data, i.e. data entered by users through Web forms and sent to the server by means of buttons or interface elements, in POST mode or in GET mode. The Web server accepts several specific URLs that can be associated with buttons so that the submission of the form triggers server-side processing. These URLs are described in the URLs and Form Actions section. This chapter covers the principles implemented in order to recover data found in forms that were returned to the server. When the 4D Web server receives a posted form, 4D can retrieve the values of any HTML objects it contains. This principle can be implemented in the case of a Web form, sent for example using WEB SEND FILE or WEB SEND BLOB, where the user enters or modifies values, then clicks on the validation button. In this case, there are two ways that 4D can retrieve the values of the HTML objects found in the request:
The WEB GET VARIABLES command retrieves the values as text, while the WEB GET BODY PART and WEB Get body part count commands can retrieve the files posted, using BLOBs. Compatibility note (4D v13.4): In previous versions, 4D copied the values of variables received by means of a posted Web form or a GET URL directly into 4D process variables (in compiled mode, these variables had to have been declared in the COMPILER_WEB method). This functioning is removed starting with 4D v13.4; it is maintained by compatibility in converted databases but can be disabled using the Automatic variable assignment compatibility option on the Compatibility page of the Database Settings (we recommend that you uncheck this option and use the WEB GET VARIABLES or WEB GET BODY PART commands in your databases). Consider the following HTML page source code: <html> <head> <title>Welcome</title> <script language="JavaScript"><!-- function GetBrowserInformation(formObj){ formObj.vtNav_appName.value = navigator.appName formObj.vtNav_appVersion.value = navigator.appVersion formObj.vtNav_appCodeName.value = navigator.appCodeName formObj.vtNav_userAgent.value = navigator.userAgent return true } function LogOn(formObj){ if(formObj.vtUserName.value!=""){ return true } else { alert("Enter your name, then try again.") return false } } //--></script> </head> <body> <form action="/4DACTION/WWW_STD_FORM_POST" method="post" name="frmWelcome" onsubmit="return GetBrowserInformation(frmWelcome)"> <h1>Welcome to Spiders United</h1> <p><b>Please enter your name:</b> <input name="vtUserName" value="" size="30" type="text"></p> <p> <input name="vsbLogOn" value="Log On" onclick="return LogOn(frmWelcome)" type="submit"> <input name="vsbRegister" value="Register" type="submit"> <input name="vsbInformation" value="Information" type="submit"></p> <p> <input name="vtNav_appName" value="" type="hidden"> <input name="vtNav_appVersion" value="" type="hidden"> <input name="vtNav_appCodeName" value="" type="hidden"> <input name="vtNav_userAgent" value="" type="hidden"></p> </form> </body> </html> When 4D sends the page to a Web Browser, it looks like this: The main features of this page are:
Let’s examine the 4D method WWW_STD_FORM_POST that is called when the user clicks on one of the buttons on the HTML form. // Retrieval of value of variables The features of this method are:
If you use a SELECT object, it is the value of the highlighted element in the object that is returned in the WEB GET VARIABLES command, and not the position of the element in the array as in 4D. WEB GET VARIABLES always returns values of the Text type. Starting with 4D v15 R3, the built-in 4D Web Server supports files uploaded in chunked transfer encoding from any Web client. Chunked transfer encoding is a data transfer mechanism specified in HTTP/1.1. It allows data to be transferred in a series of "chunks" (parts) without knowing the final data size. Note: The 4D Web Server also supports chunked transfer encoding from the server to Web clients (see WEB SEND RAW DATA). For more information about client-side implementation for chunked transfers, please refer to RFC7230 or the related page on Wikipedia. The COMPILER_WEB method, if it exists, is systematically called when the HTTP server receives a dynamic request and calls the 4D engine. This is the case, for example, when the 4D Web server receives a posted form or a URL containing the 4DCGI/ action. This method is intended to contain typing and/or variable initialization directives used during Web exchanges. It is used by the compiler when the database is compiled. The COMPILER_WEB method is common to all the Web forms. By default, the COMPILER_WEB method does not exist. You must explicitly create it. Web Services: The COMPILER_WEB project method is called, if it exists, for each SOAP request accepted. You must use this method to declare all the 4D variables associated with incoming SOAP arguments, for all methods published as Web Services. In fact, the use of process variables in Web Services methods requires that they be declared before the method is called. For more information on this point, refer to the description of the SOAP DECLARATION command.
See also
4D Transformation Tags
|
PROPERTIES
Product: 4D
HISTORY
Modified: 4D v15 R3 TAGS chunked transfer encoding, COMPILER_WEB ARTICLE USAGE
4D Language Reference ( 4D v16) |