WebFormBuild Function

Action

This function composes URL-encoded form strings similar to those specified in the dclform section. The resulting string is commonly used to add parameters to URLs or to build up messages to be sent with WebUrlPostBin.

WebFormBuild appends a pair of sLeftVal "=" sRightVal at the end of sForm. If sForm is NULL when calling WebFormBuild, "&" is added before adding the pair of sLeftVal "=" sRightVal to the result of the previous call.

Include file

WebAPI.bdh

Syntax

WebFormBuild( out   sForm       : string allownull,
              inout nMaxFormLen : number,
              in    sLeftVal    : string allownull,
              in    sRightVal   : string allownull ): boolean;

Return value

  • true if the form is generated successfully

  • false otherwise

Parameter Description
sForm Target string to be filled; NULL value allowed
nMaxFormLen Variable containing the maximum length of target string. On return it will contain the current length of the string written to sTarget.
sLeftVal Left value of form parameter, which may be NULL
sRightVal Right value of form parameter, which may be NULL
Note: For the first call of WebFormBuild, sForm must be initialized with the string to be added and nMaxFormLen must be initialized with the maximum length of the buffer of sForm. For subsequent calls, sForm must be NULL.
  • If sLeftVal/sRightVal is not NULL and not empty, it is encoded using the function StrFormEscape.

  • If sLeftVal is NULL or empty, only sRightVal is added to sForm.

  • Is sRightVal is NULL or empty, sLeftVal and "=" is added to sForm.

Example

dcltrans
  transaction TWebFormBuild
  var
    sForm     : string(1000);
    nFormSize : number;
    bOk       : boolean;
  begin
    sForm     := "http://www.MyCompany.com?";
    nFormSize := sizeof(sForm);

    bOk := WebFormBuild(sForm, nFormSize, "country", "USA");
    bOk := WebFormBuild(NULL, nFormSize, "jack@datz.com", NULL);
    bOk := WebFormBuild(NULL, nFormSize, NULL, "46&kj%= jd");

    WebUrl(sForm);
    write("form = "); write(sForm); writeln;
    sForm := ""; nFormSize := sizeof(sForm);

    bOk := WebFormBuild(sForm, nFormSize, "TestLeftVal", "TestRightVal");

    WebUrlPostBin("http://www.company.com", sForm,
                  nFormSize, "text/html");
    write("form = "); write(sForm); writeln;
  end TWebFormBuild;

Output

form = http://www%2EMyCompany%2Ecom?country=USA&
jack%40datz%2Ecom=&46%26kj%25%3D+jd
form = TestLeftVal=TestRightVal

Sample scripts

WebForms03.bdf