URLs and Form Actions

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 2003 (Modified)


The 4D Web Server offers different URLs and HTML form actions that allow you to implement various actions in your database, in both contextual and non-contextual modes.

These URLs are the following:

4DMETHOD/, to link any HTML object to a project method of your database in contextual mode,

4DACTION/, to link any HTML object to a project method of your database in non-contextual mode,

4DCGI/, to call the On Web Connection Database Method from any HTML object.

In addition, the 4D Web Server accepts several additional URLs:

/4DSTATS, /4DHTMLSTATS, /4DCACHECLEAR and /4DWEBTEST, to allow you to obtain information about the functioning of your 4D Web site. These URLs are described in the section Information about the Web Site.

/4DWSDL, to allow you to access the declaration file of Web Services published on the server. For more information, refer to the Web Services (Server) commands section and to the Design Environment manuel.

URL 4DACTION/


Syntax: 4DACTION/MyMethod{/Param}

Mode: Non-contextual. When called from contextual mode, aborts the context process and switches to non-contextual mode.

Usage: URL or Form action.

This URL allows you to link an HTML object (text, button...) to a 4D project method in non-contextual mode. The link will be /4DACTION/MyMethod/Param where MyMethod is the name of the 4D project method to be executed when the user clicks on the link and Param an optional Text parameter to pass to the method in $1 (see paragraph "The Text Parameters Passed to 4D Methods Called via URLs" below).

When 4D receives a /4DACTION/MyMethod/Param request, the On Web Authentication Database Method (if it exists) is called. If it returns True, the MyMethod method is executed.

4DACTION/ can be associated with a URL in a static Web page. The syntax of the URL must be in the following form: <A HREF="/4DACTION/MyMethod/Param">Do Something</A>

The MyMethod project method should generally return a "reply" (sending of an HTML page using SEND HTML FILE or SEND HTML BLOB, etc.). Be sure to make the processing as short as possible in order not to block the browser.

Note: A method called by 4DACTION must not call interface elements (DIALOG, ALERT...).

Warning: For a 4D method to be able to be executed using the 4DACTION/ URL, it must have the "Available through 4DACTION, 4DMETHOD and 4DSCRIPT" attribute (unchecked by default), defined in the Method properties. For more information on this point, refer to the Connection Security section.

Example

This example describes the association of the 4DACTION/ URL with an HTML picture object in order to dynamically display a picture in the page. You insert the following instructions in a static HTML page:

<IMG SRC="/4DACTION/PICTFROMLIB/1000">

The PICTFROMLIB method is as follows:

   C_TEXT($1)   `This parameter must always be declared 
   C_PICTURE($PictVar)
   C_BLOB($BlobVar)
   C_LONGINT($Number)
         `We retrieve the picture's number in the string $1
   $Number:=Num(Substring($1;2;99)) 
   GET PICTURE FROM LIBRARY($Number;$PictVar)
   PICTURE TO GIF($PictVar;$BlobVar)
   SEND HTML BLOB ($BlobVar;"Pict/gif")

4DACTION to post forms

The 4D Web server offers an additional possibility when you want to use "posted" forms, which are static HTML pages that send data to the Web server. The POST type must be associated to them and the form's action must imperatively start with /4DACTION/MethodName.

Note: A form can be submitted through two methods (both can be used with 4D):

POST, usually used to add data into the Web server - to a database,

GET, usually used to request the Web server - data coming from a database.

In this case, when the Web server receives a posted form, it calls the COMPILER_WEB project method (if it exists, see below), then the On Web Authentication Database Method (if it exists). If it returns True, the MethodName method is executed. 4D analyzes the HTML fields present in the form, retrieves their values and automatically fills the 4D variables with their contents. The field in the form and the 4D variable must have the same name.

Note: For more information, refer to the section Binding 4D objects with HTML objects.

The HTML syntax to apply in the form is of the following type:

to define the action in a form:

<FORM ACTION="/4DACTION/MethodName" METHOD=POST>

to define a field in a form:

<INPUT TYPE=Field type NAME=Field name VALUE="Default value">

For each field in the form, 4D sets the value of the field to the value of the variable with the same name. For the form options (for example, check boxes), 4D sets the associated variable to 1 if it is selected, otherwise 0.

For numerical data entries, 4D converts the value of the field from Alpha–>Real.

Note: If a field in the form is named OK (for example the Submit button), the OK system variable is set to 1 if the value of the field is not empty, otherwise it is set to 0.

Example

In a 4D Web database started and used in "non-contextual" mode, we hope that the browsers can search records by using a static HTML page. This page is called "search.htm". The database contains other static pages that allow you to, for example, display the search result ("results.htm"). The POST type has been associated to the page, as well as the /4DACTION/SEARCH action.

Here is the page as it appears in an HTML editor, in our case Adobe® PageMill™:

Here is the HTML code that corresponds to this page:

<FORM ACTION="/4DACTION/PROCESSFORM" METHOD=POST>
<INPUT TYPE=TEXT NAME=VNAME VALUE=""><BR>
<!-- Usually we put the name of the button in VALUE, for interpretation reasons, you must put a number in VALUE-->
<INPUT TYPE=CHECKBOX NAME=EXACT VALUE="1">Whole word<BR>
<!-- OK is a particular case-->
<INPUT TYPE=SUBMIT NAME=OK VALUE="Search">
</FORM>

During data entry, type "ABCD" in the data entry area, check the option and validate it by clicking the Search button.

4D then calls the COMPILER_WEB project method, which is as follows:

   C_TEXT(VNAME)
   VNAME:=""
   C_LONGINT(vEXACT)
   vEXACT:=0
   OK:=0   `particular case

In the example, VNAME contains the string "ABCD", vEXACT is equal to 1 and OK is equal to 1 (because the button's name is OK).

4D calls the On Web Authentication Database Method (if it exists), then the PROCESSFORM project method is called, which is as follows:

   If (OK=1)
      If (vEXACT=0) `If the option has not been selected
         vNAME:=VNAME+"@"
      End if
      QUERY([Jockeys];[Jockeys]Name=vNAME)
      vLIST:=Char(1)   `Return the list in HTML
      FIRST RECORD([Jockeys])
      While (Not(End selection([Jockeys])))
         vLIST:=vLIST+[Jockeys]Name+" "+[Jockeys]Tel+"<BR>"
         NEXT RECORD([Jockeys])
      End while
      SEND HTML FILE("results.htm")   `Send the list to the results.htm form
         `which contains a reference to the variable vLIST (that is <!--4DVAR vLIST––>)
   ...
   End if

URL 4DMETHOD/


Syntax: 4DMETHOD/MyMethod{/Param}

Mode: Contextual. When called from non-contextual mode, switches to contextual mode.

Usage: URL or Form action.

This URL allows you to link an HTML object (text, button...) to a 4D project method in contextual mode. The link will be /4DMETHOD/Method_Name/Param where Method_Name is the name of the 4D project method to be executed when the HTML object is clicked and Param an optional Text parameter to pass to the method in $1 (see paragraph "The Text Parameters Passed to 4D Methods Called via URLs" below). The linked item triggers the execution of the 4D project method through their URLs. The project method can itself display 4D forms, other HTML pages, and so on.

When 4D receives a /4DMETHOD request, the On Web Authentication Database Method (if it exists) is called. If it returns True, the On Web Connection Database Method (if it exists) is called, then the Method_Name method is executed with the /Param string as parameter (in $1).

If you assign /4DMETHOD/Method_Name as form action to a HTML static page, the method is executed when a Submit button of the form is clicked. To submit the HTML form on the 4D side, you need to specify the POST action 4D method that will be executed by 4D after the form is submitted. Refer to the example of the command SEND HTML FILE.

While integrating HTML pages into 4D, you will typically use normal or submit type buttons.

The HTML syntax to apply in the form is of the following type:

<FORM ACTION="/4DMETHOD/MethodName" METHOD=POST>

For more information about posted forms, refer to the previous paragraph.

Warning: For a 4D method to be able to be executed using the 4DMETHOD/ URL, it must have the "Available through 4DACTION, 4DMETHOD and 4DSCRIPT" attribute (unchecked by default), defined in the Method properties. For more information on this point, refer to the Connection Security section.

URL 4DCGI/<action>


Syntax: 4DCGI/<action>

Mode: Both.

Usage: URL.

When the 4D Web server receives the /4DCGI/<action> URL, the On Web Authentication Database Method (if it exists) is called. If it returns True, the Web server calls the On Web Connection Database Method by sending the URL "as is " to $1.

The 4DCGI/ URL does not correspond to any file. Its role is to call 4D using the On Web Connection Database Method. The "<action>" parameter can contain any type of information.

This URL allows you to perform any type of action. You just need to test the value of $1 in the On Web Connection Database Method or in one of its submethods and have 4D perform the appropriate action. For example, you can build completely custom static HTML pages to add, search, or sort records or to generate GIF images on-the-fly. Examples of how to use this URL are in the descriptions of the PICTURE TO GIF and SEND HTTP REDIRECT commands.

When issuing an action, a "response" must be returned, by using commands that send data (SEND HTML FILE, SEND HTML BLOB, etc.).

Warning: Please be sure to execute the shortest possible actions so as not to hold up the browser.

The Text Parameters Passed to 4D Methods Called via URLs


4th Dimension sends text parameters to any 4D method called via special URLs (4DMETHOD/, 4DACTION/ and 4DCGI/), in both contextual and non-contextual modes. Regarding these text parameters:

Although you do not use these parameters, you must explicitly declare them with the command C_TEXT, otherwise runtime errors will occur while using the Web to access a database that runs in compiled mode.

The $1 parameter returns the extra data placed at the end of the URL, and can be used as a placeholder for passing values from the HTML environment to the 4D environment.

Runtime Errors in Compiled Mode

Let's consider the following example. You execute a method bound to an HTML object using a link and obtain the following screen on your Web browser:

This runtime error is related to the missing declaration of the text $1 parameter in the 4D method that is called when you click on the HTML link referring to that method. As the context of the execution is the current HTML page, the error refers to the "line 0" of the method that has actually sent the page to the Web browser.

Following the example from the section Your First Time with the Web Server, you avoid the problem by explicitly declaring the text $1 parameter within the M_ADD_RECORDS and M_LIST_RECORDS methods:

      ` M_ADD_RECORDS project method
   C_TEXT($1) ` This parameter MUST be declared explicitly
   Repeat
      ADD RECORD([Customers])
   Until(OK=0)

      ` M_LIST_RECORDS project method
   C_TEXT($1) ` This parameter MUST be declared explicitly
   ALL RECORDS([Customers])
   MODIFY SELECTION([Customers])

After these changes have been made, the compiled runtime errors no longer occur.

Parameters to declare explicitly in the called 4D method

You must declare differents parameters depending on the nature and the origin of the call to a 4D method.

On Web Authentication Database Method and On Web Connection Database Method

You must declare the six parameters of the connection:

      ` On Web Connection Database Method
   C_TEXT($1;$2;$3;$4;$5;$6)

Method called by the URL 4DMETHOD/

You must declare the $1 parameter:

      ` Method called by the URL 4DMETHOD/
   C_TEXT($1)

Method called by the URL 4DACTION/

You must declare the $1 parameter:

      ` Method called by the URL 4DACTION/
   C_TEXT($1) 

Method called by the tag 4DSCRIPT/ as an HTML comment in a document

The method should return a value in $0. You must declare the $0 and $1 parameter:

      ` Method called by the tag 4DSCRIPT/ as an HTML comment
   C_TEXT($0; $1)

See Also

Binding 4D objects with HTML objects, GET WEB FORM VARIABLES, Using the Contextual Mode, Your First Time with the Web Server.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next