예제 #1
0
 /**
  * Determines if the given string is a reference to the meta data. If it is, it converts it to
  * a key for accessing the _meta array and returns true. If not, it leaves it alone and returns false.
  *
  * Meta data is always accessed using a single underscore as the first character.
  **/
 public static function _isMeta(&$s)
 {
     fxAssert::isNonEmptyString($s, '$s');
     if (mb_substr($s, 0, 1) === '_' && mb_strlen($s) > 1) {
         $s = mb_substr($s, 1);
         return true;
     }
     return false;
 }
예제 #2
0
파일: fxForm.php 프로젝트: netcarver/fxForm
 /**
  * Constructor for a form.
  *
  * Creates a named form with the given parameters.
  * Also sets the id of the form to "form-$name" (simplifying the contents of the $name in the process).
  * If this isn't what you want just overwrite the id by setting your own straight after the form is constructed and before you
  * call add() to put elements into your form.
  * This id of the form will be used as a prefix to the id of everything you then add to the form so there should be no collisions
  * between form-generated ids and ids you use elsewhere in your pages.
  **/
 public function __construct($name, $action, $method = "post")
 {
     fxAssert::isNonEmptyString($name, 'name', "Form must be named.");
     parent::__construct($name);
     $method_wl = array('post', 'get');
     $method = strtolower($method);
     fxAssert::isInArray($method, $method_wl);
     $this->_method = $method;
     $this->_action = $action;
     $this->id = self::_simplify("form-{$name}");
     $this->errors = array();
 }
예제 #3
0
 protected static function makeDatalist($name, &$options)
 {
     fxAssert::isNonEmptyString($name);
     fxAssert::isArray($options, 'options');
     $name = fxForm::_simplify($name);
     $o[] = '';
     $o[] = '<datalist id="' . $name . '">';
     if (!empty($options)) {
         foreach ($options as $v) {
             $o[] = "\t<option value=\"" . htmlspecialchars($v) . '">';
         }
     }
     $o[] = '</datalist>';
     $o = implode("\n", $o);
     return $o;
 }
예제 #4
0
 /**
  * Adds the given error message to the supplied error array and the element's
  * error array.
  **/
 public function _addError($msg = '', &$errors = null)
 {
     fxAssert::isNonEmptyString($msg, '$msg');
     fxAssert::isArray($errors);
     $errors[$this->name][] = $msg;
     $this->_meta['errors'][] = $msg;
     return $this;
 }