creditcard.php
Go to the documentation of this file.
1 <?php
10 namespace depage\htmlform\elements;
11 
45 class creditcard extends fieldset
46 {
56  protected function setDefaults()
57  {
58  parent::setDefaults();
59 
60  $this->defaults['required'] = false;
61  $this->defaults['labelNumber'] = "Creditcard Number";
62  $this->defaults['labelCheck'] = "CVV/CVC";
63  $this->defaults['labelExpirationDate'] = "Expiration Date MM/YY";
64  $this->defaults['labelOwner'] = "Card Owner";
65  $this->defaults['cardtypes'] = array(
66  "visa",
67  "americanexpress",
68  "mastercard",
69  );
70  }
71 
79  public function addChildElements()
80  {
81  parent::addChildElements();
82 
83  $cardnames = array(
84  'visa' => "Visa",
85  'americanexpress' => "American Express",
86  'mastercard' => "MasterCard",
87  );
88  $options = array();
89  foreach ($this->cardtypes as $card) {
90  if (isset($cardnames[$card])) {
91  $options[$card] = $cardnames[$card];
92  }
93  }
94 
95  $this->addSingle($this->name . "_card_type", array(
96  'label' => "",
97  'list' => $options,
98  'skin' => 'select',
99  ));
100  $this->addText($this->name . "_card_number", array(
101  'label' => $this->labelNumber,
102  'required' => $this->required,
103  'validator' => "/^(?:\d[ -]*?){13,16}$/",
104  ));
105  $this->addText($this->name . "_card_numbercheck", array(
106  'label' => $this->labelCheck,
107  'required' => $this->required,
108  'validator' => "/^\d{3,4}$/",
109  ));
110  $this->addText($this->name . "_card_expirydate", array(
111  'label' => $this->labelExpirationDate,
112  'required' => $this->required,
113  'validator' => "/^\d{2}\/\d{2}$/",
114  ));
115  $this->addText($this->name . "_card_owner", array(
116  'label' => $this->labelOwner,
117  'required' => $this->required,
118  ));
119  }
120 
129  public function validate()
130  {
131  return parent::validate();
132  }
133 }
134 
135 /* vim:set ft=php sw=4 sts=4 fdm=marker et : */
setDefaults()
collects initial values across subclasses.
Definition: creditcard.php:56
validate()
Validate the creditcard data.
Definition: creditcard.php:129
addChildElements()
adds creditcard-inputs to fieldset
Definition: creditcard.php:79
Default creditcard fieldset.
Definition: creditcard.php:45
The fieldset class holds HTML-fieldset specific attributes and methods.
Definition: fieldset.php:50