DLG_UCHKOUT Dialog Component

Description

Captures or displays the customer information required by the billing and shipping processes.

Discussion

The DLG_UCHKOUT dialog component is part of the checkout process. It captures or displays the customer information required by the billing and shipping processes. The DLG_UCHKOUT dialog component contains the text controls necessary to enter a new customer table record or display an existing record. The DLG_UCHKOUT dialog illustrates the use of merge controls and headings. The component uses client side expressions to show and hide a heading used to show an error. The controls have the same names as the fields in the customer table.

 Containers

CHECKOUTUSER.A5W

  •  ShowError

    •  Property

      Control Settings > Control Type

    • Set to "Hidden".

  •  HeadingError

    •  Property

      Control Settings > Control Type

    • Set to "Heading".

    •  Property

      Control Settings > Show/Hide Expression

    • Expression ShowError !=""

    •  Property

      Heading Properties

    • Text set to "Your information can not be found. Please re-enter".

  •  Heading1

    •  Property

      Control Settings > Control Type

    • Set to "Heading".

    •  Property

      Heading Properties

    • Text set to "Personal Information".

  •  customer_id

    •  Property

      Control Settings > Control Type

    • Set to "Hidden".

  •  Merge Cells Begin.3

    •  Property

      Merge Cells Properties > Row headings

    • Set to "Name (First, Last) ".

  •  Firstname

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE. General > Custom error message set to "First Name Required"

    •  Property

      Control Settings > Client side validation

    • Set to TRUE.

  •  Lastname

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE. General > Custom error message set to "Last Name Required"

    •  Property

      Control Settings > Client side validation

    • Set to TRUE.

  •  Merge Cells End.3

  •  Merge Cells Begin.1

    •  Property

      Merge Cells Properties > Row headings

    • Set to "City, St, Zip ". Bill_city, Bill_state_region, and Bill_postal_code controls in merged section

  •  Bill_state_region

    •  Property

      Control Settings > Control Type

    • Set to "Dropdown".

    •  Property

      DropDownBox Properties > Choices

    • Define Choices > List type is set to "Dynamic". Data Source > Data source type is set to "Variable". Data Source > Variable name is set to "states".

  •  Merge Cells End.1

  •  Heading2

    •  Property

      Control Settings > Control Type

    • Set to "Heading".

    •  Property

      Heading Properties

    • Text set to "Shipping Information".

  •  Ship_same

    •  Property

      Row Properties

    • Freeform layout set to TRUE. Freeform template set to "{ship_same}". The template will be replaced in the Activate event code.

  •  Ship_to_Address_1

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE.

    •  Property

      Control Settings > Client side validation

    • Set to TRUE.

  •  Merge Cells Begin.2

    •  Property

      Merge Cells Properties > Row headings

    • Set to "City, St, Zip ".

  •  Ship_City

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE.

    •  Property

      Control Settings > Client side validation

    • Set to TRUE.

  •  Ship_state_region

    •  Property

      Control Settings > Control Type

    • Set to "Dropdown".

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE.

    •  Property

      DropDownBox Properties > Choices

    • Define Choices > List type is set to "Dynamic". Data Source > Data source type is set to "Variable". Data Source > Variable name is set to "states".

  •  Ship_postal_code

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE.

    •  Property

      Control Settings > Client side validation

    • Set to TRUE.

  •  Merge Cells End.2

  •  Heading3

    •  Property

      Control Settings > Control Type

    • Set to "Heading".

    •  Property

      Heading Properties

    • Text set to "Contact Information".

  •  Email

    •  Property

      Control Settings > Validation rules

    • General > Enable rules set to TRUE. General > Require value set to TRUE. Text Format > Regular Expression set to "\bA-Z0-9a-z._%-+@A-Z0-9a-z._%-+\.A-Za-z{2,4}\b".

 Notable Component Property Settings

 Event Code

The Validate event code checks if the entered email already exists in the customer file. If one is found, it compares the customer_id from that record with the customer_id for the current user. The values should match if the record found is for the current customer.

chkcust = table.external_record_content_get("PathAlias.ADB_Path\customer.dbf","customer_id","email","email=\""+alltrim(CurrentForm.Controls.Email.value)+"\"")
if chkcust <> ""
    if chkcust <> alltrim(CurrentForm.Controls.customer_id) ' email already exists for another customer
        CurrentForm.Has_Error = .T.
        CurrentForm.Error_Message = "A Registered User with this email already exists. Please correct or Log In"
    end if
end if

The AfterValidate event code starts by checking the session.dataclear variable. If it is TRUE, there is no data to validate and the script exits.

if eval_valid("session.dataclear")
    if session.dataclear = .T. ' skip validate if clearing data
        end
    end if
end if

Next, the script sets session.protectedchkoutprogress to 2, indicating that this page is complete.

session.protectedchkoutprogress = 2

The following statements copy the values in the various controls on the dialog component into the session.protectedchkout dot variable.

dim session.protectedchkout as p
session.protectedchkout.Firstname = alltrim(CurrentForm.Controls.Firstname)
session.protectedchkout.Lastname = alltrim(CurrentForm.Controls.Lastname)
session.protectedchkout.Company = alltrim(CurrentForm.Controls.company)
session.protectedchkout.Email = alltrim(CurrentForm.Controls.Email)
session.protectedchkout.Phone = transform(remspecial(CurrentForm.Controls.phone),"@R (999) 999-9999") ' convert to standard mask template
session.protectedchkout.Bill_address_1 = alltrim(CurrentForm.Controls.Bill_address_1)
session.protectedchkout.Bill_address_2 = alltrim(CurrentForm.Controls.Bill_address_2)
session.protectedchkout.Bill_city = alltrim(CurrentForm.Controls.Bill_city)
session.protectedchkout.Bill_state_region = alltrim(CurrentForm.Controls.Bill_state_region)
session.protectedchkout.Bill_postal_code = alltrim(CurrentForm.Controls.Bill_postal_code)
session.protectedchkout.Ship_to_name = alltrim(CurrentForm.Controls.Ship_to_Name)
session.protectedchkout.Ship_address_1 = alltrim(CurrentForm.Controls.Ship_address_1)
session.protectedchkout.Ship_address_2 = alltrim(CurrentForm.Controls.Ship_address_2)
session.protectedchkout.Ship_city = alltrim(CurrentForm.Controls.Ship_City)
session.protectedchkout.Ship_same = alltrim(CurrentForm.Controls.Ship_same)
session.protectedchkout.Ship_state_region = alltrim(CurrentForm.Controls.Ship_state_region)
session.protectedchkout.Ship_postal_code = alltrim(CurrentForm.Controls.Ship_postal_code)
session.protectedchkout.Customer_id = alltrim(CurrentForm.Controls.customer_id)

If the customerid control has a non-null value, the script uses this value to retrieve the corresponding record from the customer table.

if CurrentForm.Controls.customerid <> "" ' values came from a table record
    query.filter = "customer_id = " + quote(CurrentForm.Controls.customerid) ' find the record
    query.order = ""
    tbl = table.open("PathAlias.ADB_Path\customer.dbf")
    qdx = tbl.query_create()

If the query finds a single record, then the script writes the values in the dialog's controls into the fields of the customer record.

if qdx.records_get()= 1 then 'record found - update
        tbl.change_begin()
        tbl.Firstname = alltrim(CurrentForm.Controls.Firstname)
        tbl.Lastname = alltrim(CurrentForm.Controls.Lastname)
        tbl.Company = alltrim(CurrentForm.Controls.company)
        tbl.Email = alltrim(CurrentForm.Controls.Email)
        tbl.Phone = transform(remspecial(CurrentForm.Controls.phone),"@R (999) 999-9999") ' convert to standard mask template
        tbl.Bill_address_1 = alltrim(CurrentForm.Controls.bill_address_1)
        tbl.Bill_address_2 = alltrim(CurrentForm.Controls.bill-address_2)
        tbl.Bill_city = alltrim(CurrentForm.Controls.bill_city)
        tbl.Bill_state_region = alltrim(CurrentForm.Controls.bill_state_region)
        tbl.Bill_postal_code = alltrim(CurrentForm.Controls.Bill_postal_code)
        tbl.Ship_to_name = alltrim(CurrentForm.Controls.Ship_to_Name)
        tbl.Ship_address_1 = alltrim(CurrentForm.Controls.Ship_to_Address_1)
        tbl.Ship_address_2 = alltrim(CurrentForm.Controls.Ship_to_Address_2)
        tbl.Ship_city = alltrim(CurrentForm.Controls.Ship_City)
        tbl.Ship_state_region = alltrim(CurrentForm.Controls.Ship_state_region)
        tbl.Ship_postal_code = alltrim(CurrentForm.Controls.Ship_to_Zip)
        if alltrim(CurrentForm.Controls.ship_same) = "True"
            tbl.Ship_same = .T.
        else
            tbl.Ship_same = .F.
        end if
        tbl.change_end()
    end if
    tbl.close()
end if

Finally the script sets CurrentForm.RedirectTarget to next desired page.

'NOTE: to use PayPal pages, uncomment out first line and comment out second line
'CurrentForm.RedirectTarget = "checkoutcompPayPal.a5w"
CurrentForm.RedirectTarget = "checkoutcomp.a5w"

The Activate event code first sets the ShowError value to blank to hide the heading. It then populates a list for the state dropdown controls, and gets a list of editable controls on the dialog. Some controls are not editable and are removed from the list of controls.

CurrentForm.Controls.ShowError.value = ""
dim states as c ' populate state list for dropdowns
states = ""+crlf()+cstates("A"+crlf()) ' add blank first entry
dim Control_list as c
Control_list = properties_enum(CurrentForm.Controls)
dim remove as c ' controls to ignore
remove = <<%text%
ShowError
HeadingError
Heading1
Heading2
Heading3
%text%
Control_list = filter_string_multi(Control_list,remove,crlf(),.T.)
Control_list = remove_blank_lines(control_list)

The event code next tests to see if the session.dataclear variable exists and is TRUE. If so, it loops through the editable control list to erase the values of the dialog's controls and the session.protectedchkout variable, then exits. Finally, it sets session.dataclear to FALSE.

if eval_valid("session.dataclear") = .T. then
    if session.dataclear = .t. then
        for each foo in Control_list
            eval("CurrentForm.Controls."+ foo +".value") = ""
            eval("session.protectedchkout."+foo) = ""
        next
        session.dataclear = .F. 'clear once unless reset on page
        end
    end if
end if

The next step is to test if the session.enteruserdata variable (a customer ID) exists and is NULL. If this is the case, the script copies the data from session.protectedchkout into the dialog's controls. This variable contains data saved info from a previous visit to this page.

if eval_valid("session.enteruserdata") then
    if session.enteruserdata = "" then
        if eval_valid("session.protectedchkout")
            for each foo in Control_list
                  if eval_valid("session.protectedchkout."+foo)
                        eval("CurrentForm.Controls."+foo+".value") = eval("session.protectedchkout."+foo)
                  end if 
            next
        end if

If the session.enteruserdata variable contains data, the script uses it to find the appropriate customer record. If it finds a record, the script copies the record data into the dialog's controls. If a single record can not be found for the current customer_id, the ShowError control will have a value and the error heading will display.

else
        query.filter = "alltrim(customer_id) = " + quote(session.enteruserdata)
        query.order = ""
        tbl = table.open("PathAlias.ADB_Path\customer.dbf")
        qdx = tbl.query_create()
        if qdx.records_get()= 1 then 'record found
            CurrentForm.Controls.customer_id = alltrim(tbl.Customer_id)
            CurrentForm.Controls.Firstname = alltrim(tbl.Firstname)
            CurrentForm.Controls.Lastname = alltrim(tbl.Lastname)
            CurrentForm.Controls.company = alltrim(tbl.Company)
            CurrentForm.Controls.Email = alltrim(tbl.Email)
            CurrentForm.Controls.phone = alltrim(tbl.Phone)
            CurrentForm.Controls.Bill_address_1 = alltrim(tbl.Bill_address_1)
            CurrentForm.Controls.Bill_address_2 = alltrim(tbl.Bill_address_2)
            CurrentForm.Controls.Bill_city = alltrim(tbl.Bill_city)
            CurrentForm.Controls.Bill_state_region = alltrim(tbl.Bill_state_region)
            CurrentForm.Controls.Bill_postal_code = alltrim(tbl.Bill_postal_code)
            if tbl.Ship_same = .T.
                CurrentForm.Controls.Ship_to_Name = alltrim(tbl.Firstname) + " "+alltrim(tbl.Lastname)
                CurrentForm.Controls.Ship_to_Address = alltrim(tbl.Bill_address_1)
                CurrentForm.Controls.saddr2 = alltrim(tbl.Bill_address_2)
                CurrentForm.Controls.Ship_to_City = alltrim(tbl.Bill_city)
                CurrentForm.Controls.Ship_to_State = alltrim(tbl.Bill_state_region)
                CurrentForm.Controls.Ship_to_Zip = alltrim(tbl.Bill_postal_code)
                CurrentForm.Controls.Ship_same = "True" 
            else 
                CurrentForm.Controls.Ship_to_Name = alltrim(tbl.Ship_to_name)
                CurrentForm.Controls.Ship_to_Address = alltrim(tbl.Ship_address_1)
                CurrentForm.Controls.saddr2 = alltrim(tbl.Ship_address_2)
                CurrentForm.Controls.Ship_to_City = alltrim(tbl.Ship_city)
                CurrentForm.Controls.Ship_to_State = alltrim(tbl.Ship_state_region)
                CurrentForm.Controls.Ship_to_Zip = alltrim(tbl.Ship_postal_code)
                CurrentForm.Controls.Ship_same = "False" 
            end if
        else
            CurrentForm.Controls.ShowError = "yes"
        end if
        tbl.close()
    end if

Next, the script sets session.enteruserdata to NULL.

session.enteruserdata = ""

If session.enteruserdata does not exist, but session.protectedchkout does exist, the script copies the contents of session.protectedchkout into the dialog's controls.

elseif eval_valid("session.protectedchkout")
    for each foo in Control_list
        if eval_valid("session.protectedchkout."+foo)
            eval("CurrentForm.Controls."+foo + ".value") = eval("session.protectedchkout."+foo)
        end if
    next
end if

Finally, the freeform template for ship_same is modified based on the current value in the ship_same control. The control includes on onclick event that calls a JavaScript function on the CHECKOUTUSER.A5W page.

if CurrentForm.Controls.ship_same = "True"
    CurrentForm.Controls.ship_same.column.FreeFormTemplate = <<%html%

%html%
else
    CurrentForm.Controls.ship_same.column.FreeFormTemplate = <<%html%

%html%
end if

See Also