1 <?php
2 /**
3 * NummberInput.php
4 *
5 * @author Elvyrra SAS
6 * @license http://rem.mit-license.org/ MIT
7 */
8
9 namespace Hawk;
10
11 /**
12 * This class describes the behavio of number inputs
13 *
14 * @package Form\Input
15 */
16 class NumberInput extends FormInput{
17 const TYPE = "number";
18
19 /**
20 * Check the submitted value of the input
21 *
22 * @param Form $form The form the input is associated with
23 *
24 * @return bool True if the submitted value is valid, else false
25 */
26 public function check(&$form = null){
27 // Start by checking general validators
28 if(parent::check($form)) {
29 if(!empty($this->value) && !is_numeric($this->value)) {
30 // The value is not numeric
31 $form->error($this->errorAt, Lang::get('form.number-format'));
32 return false;
33 }
34 elseif(isset($this->minimum) && $this->value < $this->minimum) {
35 // The value is lower than the given minimum
36 $form->error($this->errorAt, Lang::get("form.number-minimum", array('value' => $this->minimum)));
37 return false;
38 }
39 elseif(isset($this->maximum) && $this->value > $this->maximum) {
40 // The value is greater than the given maximum
41 $form->error($this->errorAt, Lang::get("form.number-maximum", array('value' => $this->maximum)));
42 return false;
43 }
44 // The value is valid
45 return true;
46 }
47 else{
48 return false;
49 }
50 }
51 }
52