wwRequest::FormVarsToObject

Parses an object and pulls form variables from the request buffer by matching the property names to the request variables.

Optionally you can pass in a prefix for form variables to allow for potential naming problems for properties of multiple objects.

Ideally you pass in existing object and Web Connection will populate the properties of the object from the form variables.

If you don't pass an object a generic object is created for you with properties for each of the form variables of the HTML form and populated with String values (requires VFP8 or later).

This method can be extremely useful for reducing form variable retrieval code from your Web applications especially if you map form fields directly to objects. Form variables must match the property names either directly or with an optional prefix (such as txt, but the prefix must consistent for all variables).


o.FormVarsToObject(loObject,lcPrefix)                            

Return Value

nothing. Object passed in as parameter is filled with values.

Parameters

loObject
An existing object to be imported to. Code walks the object structure (1 dimensionally) by looking for form vars.

lcPrefix
An optional prefix that can be used in form variables. This prefix is stripped when matching property values.


Remarks

Logical values are handled from checkboxes, but non-logical checkbox values will not be captured when not checked. Selection values for checkboxes must be On or True in order to be recognized as a True value for a logical. Multiselect lists or multiple selection radios will pull only the first selection into the target property.

Object and array members are ignored and not filled or updated. Date values are imported with CTOD and CTOT. There may be formatting problems so these properties may require post processing and potential problems with SET STRICTDATE settings.

You can work around any misparsing problems by performing additional post processing on the captured object data or handling any fields that might have been missed manually.

This method may cause problems when capturing logical values into object proeprties that are not part of the form displayed. This comes from the HTML limitation of checkboxes and radios not returning an unchecked value. The method assumes that any logical value not found in the request data is false. This can cause any properties not on the form to be forced to a value of .F. even though the original value was .T. The workaround is to capture any non-participating logical value to tempoary vars and then restore them after the method call is completed.


Example

*** Using a cursor
USE wws_Customer
SCATTER NAME loCustomer MEMO BLANK

Request.FormVarsToObject(loCustomer)


*** Using a 'real' business object loCust = CREATE("cCustomer") loCust.New() *** Store form vars to oData properties Request.FormVarsToObject(loCust.oData) IF !loCust.Validate() THIS.Errormsg("Invalid Data") RETURN ENDIF loCust.Save()
*** Without an object passed in loFormVars = Request.FormVarsToObject() *** Retrieve the txtName and txtCompany variables lcName = loFormVars.txtName lcCompany = loFormVars.txtCompany

See also:

Class wwrequest


  Last Updated: 7/25/2005 | © West Wind Technologies, 2008