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: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
<?php
class FormFieldConstraintLengthMax extends AbstractFormFieldConstraint
{
private $error_message;
private $upper_bound;
public function __construct($upper_bound, $js_message = '')
{
if (empty($js_message))
{
$js_message = LangLoader::get_message('form.doesnt_match_length_max', 'status-messages-common');
}
$this->error_message = StringVars::replace_vars($js_message, array('upper_bound' => $upper_bound));
$this->set_validation_error_message($this->error_message);
$this->upper_bound = $upper_bound;
}
public function validate(FormField $field)
{
$value = TextHelper::strlen($field->get_value());
$is_required = $field->is_required();
if (!empty($value) || $is_required)
{
return ($value <= $this->upper_bound);
}
return true;
}
public function get_js_validation(FormField $field)
{
return 'lengthMaxFormFieldValidator(' . TextHelper::to_js_string($field->get_id()) . ', ' . $this->upper_bound . ', ' . TextHelper::to_js_string($this->error_message) . ')';
}
}
?>