When creating a purchase order you need to gather the user's billing information as well as their shipping information. The user might want their order shipped to their billing address, in which case their shipping address is the same as their billing address. At other times they might want their order shipped elsewhere, as in the case of purchasing a gift for someone else.
In this task we will create the shipping/billing section of a purchase order form and focus on how to reliably allow the user to specify whether to use their billing information as the shipping information. Let's start by designing a new blank form.
Create the schema:
- Open the Data Source task pane.
- Double-click myFields and rename it to Order.
- Add a Group named Billing.
- Add a Group named Shipping.
- Select the Billing group, and then add eight Text Fields named Name, Street1, Street2, City, State, PostalCode, Phone, and Email.
- Right-click the Name text field, choose Reference, select the Shipping group, and then click OK.
- Perform the previous step for each of the seven remaining text fields in the Billing group, preserving their order.
- Select the Shipping group and then add a True/False Attribute Field named sameAsBilling with its default value set to False.
We have just created a schema that will allow us to gather billing and shipping information for a purchase order. Figure 1 shows the completed schema in the Data Source task pane. The shipping information contains the same fields as the billing information with the addition of a Boolean value to allow the user to indicate whether they want their order shipped to their billing address or somewhere different. Now let's create the view.

Figure 1. The purchase order data source
Design the view layout:
- Choose Font from the Format menu.
- In the Font task pane, select Heading 2.
- At the top of the view, type PURCHASE ORDER, and then press Enter.
- Insert a 1 x 2 Layout Table into the view.
- In the left cell of the layout, type Billing Information:, and then press Enter.
- In the Data Source task pane, right-click the Billing group, choose Controls In Layout Table, and then drag the right edge of the inserted billing layout table to use the remaining space of the containing layout table cell.
- In the right cell of the layout table, type Shipping Information ():, and then press Enter.
- In the Data Source task pane, right-click the Shipping group, choose Controls In Layout Table, and then drag the right edge of the inserted shipping layout table to use the remaining space of the containing layout table cell.
- Select the text Same As Billing and its associated check box, drag-and-drop it between the parentheses on the line above, and then remove the extra line breaks that were inserted during the drop.
- Select the two empty cells remaining from where we just moved the text and check box, and then press Delete.
The view is now laid out, and the results can be seen in Figure 2. At this point the user can fill in their billing and shipping information, but the Same As Billing check box is non-functional. Let's add two rules on the check box such that when it is selected, the billing fields are copied to the shipping fields, and when the check box is cleared, the shipping fields are cleared.

Figure 2. The completed purchase order layout
Add a rule to the check box to copy the billing fields:
- Double-click the Same As Billing check box.
- In the Check Box Properties dialog box, click Rules, and then click Add.
- Name the rule Copy Billing Fields, and then click Set Condition.
- In the Condition dialog box, select True in the third drop-down list, as shown in Figure 3, and then click OK.
- Click Add Action.
- In the Action dialog box, select Set A Field's Value from the Action drop-down list.
- Click the Select XPath button to the right of the Field text box, select Shipping/Name, and then click OK.
- Click the Insert Formula button to the right of the Value text box, click Insert Field Or Group, select the Billing/Name field, and then click OK three times.
- Add seven more actions to this rule to copy the remaining fields from the Billing group to the Shipping group.
- Click OK to complete this rule.

Figure 3. Setting the rule condition
Add a rule to the check box to clear the shipping fields:
- In the Rules dialog box, click Add.
- Name the rule Clear Shipping Fields, and then click Set Condition.
- In the Condition dialog box, select False in the third drop-down list, and then click OK.
- Click Add Action.
- In the Action dialog box, select Set A Field's Value from the Action drop-down list.
- Click the Select XPath button to the right of the Field text box, select Shipping/Name, and then click OK twice, leaving the Value text box blank.
- Add seven more actions to this rule to clear the remaining fields in the Shipping group.
- Click OK three times to close all open dialog boxes.
Previewing the form at this point, you will find that any values you enter into the billing fields are copied to the shipping fields when you select the Same As Billing check box, and that each of the shipping fields are cleared when you clear the check box. But there are a couple of issues that need to be resolved.
First, when the Same As Billing check box is selected, you can still change the values in the shipping fields, effectively making the check box inaccurate. Second, when the check box is selected, any changes you make to the billing fields are not reflected in the shipping fields. Let's make the changes necessary to correct these issues.
Prevent the user from changing the shipping fields:
- Double-click the Name field in the shipping column.
- On the Display tab of the Text Box Properties dialog box, click Conditional Formatting, and then click Add.
- Select sameAsBilling in the first condition drop-down list, and then select True in the third condition drop-down list.
- Select the Read-Only formatting check box, and then click OK three times to close all open dialog boxes.
- Add this same conditional formatting to each of the seven remaining shipping fields in the view.
Ensure that the shipping fields reflect changes made to the billing fields:
- Double-click the Name field in the billing column.
- On the Data tab of the Text Box Properties dialog box, click Rules, and then click Add.
- Name the rule Copy Changes to Shipping Name, and then click Set Condition.
- Select Select A Field Or Group in the first condition drop-down list.
- In the Select A Field Or Group dialog box, select the Shipping/sameAsBilling field, and then click OK.
- Select True in the third condition drop-down list, and then click OK.
- Click Add Action.
- In the Action dialog box, select Set A Field's Value from the Action drop-down list.
- Click the Select XPath button to the right of the Field text box, select Shipping/Name, and then click OK.
- Click the Insert Formula button to the right of the Value text box, click Insert Field Or Group, select the Billing/Name field, and then click OK six times to close all open dialog boxes.
- Add similar rules, naming them appropriately, to each of the seven remaining billing fields in the view.
With these last two changes our billing/shipping section is complete. The user can enter separate billing and shipping information or choose to have their shipping information be the same as their billing information by selecting the Same As Billing check box. If the user selects the latter option, the shipping data will accurately reflect the most current billing information, even if changes are made to the billing information.
Try it:
Preview the form and test your new billing/shipping section with and without the Same As Billing check box selected. The completed form is shown in Figure 4.

Figure 4. The completed purchase order billing/shipping section
©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.