ProductOrderListStep.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
 * First step of the ProductOrder form. @link<ProductOrderMultiForm>
 *
 */
class ProductOrderListStep extends MultiFormStep
{
    protected static $next_steps = 'ProductOrderSummaryStep';

    function getFields()
    {
        $productList = $this->ProductList();
        $fields = new FieldSet();
        foreach ($productList as $product){
            $fields->push(new LiteralField('Code', "$product->code"), 'Code');
            $fields->push(new HiddenField("code_$product->code", '', "$product->code"));
            $fields->push(new LiteralField('name', "$product->name"), 'Name');
            $fields->push(new HiddenField("name_$product->code", '', "$product->name"));
            $fields->push(new TextField("quantity_$product->code", 'Quantity', '', 3), 'testkey');
            $fields->push(new DropdownField("size_$product->code", 'Size', array('2qt'=>'2 Quart Jug', '5gal'=>'5 Gallon Jug','25gal'=>'25 Gallon Barrel')));
        };
        return $fields;
    }

    /**
     * Provides the ProductObjects needed to populate order form.
     *
     * @return <type> DataObjectSet of ProductObjects from a specific sub-class.
     */
    public function ProductList()
    {
        return DataObject::get('ProductObjectCarwash', '','`Code` ASC');
    }


}
?>

print_r of submitted form data (plain_text)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Array
(
    [code_499] => 499
    [name_499] => ProductTesting
    [quantity_499] => 1
    [size_499] => 2qt
    [code_500] => 500
    [name_500] => Self Serve Concentrated Presoak
    [quantity_500] => 2
    [size_500] => 5gal
    [code_501] => 501
    [name_501] => Foamy Hot Presoak/Shampoo
    [quantity_501] => 3
    [size_501] => 25gal
    [code_502] => 502
    [name_502] => Heavy Duty Alkaline Presoak
    [quantity_502] => 4
    [size_502] => 2qt
)