textfield.class.inc.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Form\Field;
  19. use \Combodo\iTop\Form\Field\Field;
  20. /**
  21. * Description of TextField
  22. *
  23. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  24. */
  25. abstract class TextField extends Field
  26. {
  27. /**
  28. * Checks the validators to see if the field's current value is valid.
  29. * Then sets $bValid and $aErrorMessages.
  30. *
  31. * @return boolean
  32. */
  33. public function Validate()
  34. {
  35. $this->SetValid(true);
  36. $this->EmptyErrorMessages();
  37. foreach ($this->GetValidators() as $oValidator)
  38. {
  39. if (!preg_match($oValidator->GetRegExp(true), $this->GetCurrentValue()))
  40. {
  41. $this->SetValid(false);
  42. $this->AddErrorMessage($oValidator->GetErrorMessage());
  43. }
  44. }
  45. return $this->GetValid();
  46. }
  47. }