Creditcard.php
Go to the documentation of this file.
1<?php
11
45class Creditcard extends Fieldset
46{
50 protected $labelNumber;
51
55 protected $labelCheck;
56
61
65 protected $labelOwner;
66
70 protected $cardtypes;
80 protected function setDefaults()
81 {
82 parent::setDefaults();
83
84 $this->defaults['required'] = false;
85 $this->defaults['labelNumber'] = "Creditcard Number";
86 $this->defaults['labelCheck'] = "CVV/CVC";
87 $this->defaults['labelExpirationDate'] = "Expiration Date MM/YY";
88 $this->defaults['labelOwner'] = "Card Owner";
89 $this->defaults['cardtypes'] = array(
90 "visa",
91 "americanexpress",
92 "mastercard",
93 );
94 }
95
103 public function addChildElements()
104 {
105 parent::addChildElements();
106
107 $cardnames = array(
108 'visa' => "Visa",
109 'americanexpress' => "American Express",
110 'mastercard' => "MasterCard",
111 );
112 $options = array();
113 foreach ($this->cardtypes as $card) {
114 if (isset($cardnames[$card])) {
115 $options[$card] = $cardnames[$card];
116 }
117 }
118
119 $this->addSingle($this->name . "_card_type", array(
120 'label' => "",
121 'list' => $options,
122 'skin' => 'select',
123 ));
124 $this->addText($this->name . "_card_number", array(
125 'label' => $this->labelNumber,
126 'required' => $this->required,
127 'validator' => "/^(?:\d[ -]*?){13,16}$/",
128 ));
129 $this->addText($this->name . "_card_numbercheck", array(
130 'label' => $this->labelCheck,
131 'required' => $this->required,
132 'validator' => "/^\d{3,4}$/",
133 ));
134 $this->addText($this->name . "_card_expirydate", array(
135 'label' => $this->labelExpirationDate,
136 'required' => $this->required,
137 'validator' => "/^\d{2}\/\d{2}$/",
138 ));
139 $this->addText($this->name . "_card_owner", array(
140 'label' => $this->labelOwner,
141 'required' => $this->required,
142 ));
143 }
144
153 public function validate()
154 {
155 return parent::validate();
156 }
157}
158
159/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Default creditcard fieldset.
addChildElements()
adds creditcard-inputs to fieldset
validate()
Validate the creditcard data.
$cardtypes
list of cardtypes to choose from
$labelNumber
label for the creditcard-number field
$labelOwner
label for the creditcard-owner field
setDefaults()
collects initial values across subclasses.
$labelCheck
label for the creditcard-check field
$labelExpirationDate
label for the creditcard-expirydate field
The fieldset class holds HTML-fieldset specific attributes and methods.
Definition Fieldset.php:51
Classes for HTML input-elements.
Definition Address.php:9