Source of file QuantityField.php
Size: 1,051 Bytes - Last Modified: 2021-12-24T05:16:24+00:00
/var/www/docs.ssmods.com/process/src/code/forms/QuantityField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445 | <?php /** * Text input field with validation for numeric values. * * @package forms * @subpackage fields-formattedinput */ class QuantityField extends NumericField { public function Type() { return 'quantity numeric text'; } /** PHP Validation **/ public function validate($validator) { // First check if value is numeric if ($this->value && $this->isNumeric()) { // Convert to a number to check $value = $this->value + 0; if(is_int($value)) { return true; } } $validator->validationError( $this->name, _t( 'Checkout.VALIDATION', '{value} is not a valid number, only whole numbers can be accepted for this field', array('value' => $this->value) ), "validation" ); return false; } public function dataValue() { return (is_numeric($this->value)) ? $this->value : 0; } } |