Ejemplo n.º 1
0
 public function __construct($id, $action, $attrs, IFormlet $formlet)
 {
     if (!preg_match("#[a-zA-Z][a-zA-Z0-9_]+#", $id)) {
         throw new Exception("Form::__construct: '{$id}' can not be used as " . "id. Only use numbers and digits.");
     }
     C::guardIsFormlet($formlet);
     C::guardIsString($id);
     C::guardIsString($action);
     $attrs = Value::defaultTo($attrs, array());
     C::guardEachAndKeys($attrs, "C::guardIsString", "C::guardIsString");
     $this->_id = $id;
     $this->_input = null;
     $this->_result = null;
     $attrs["method"] = "post";
     $attrs["action"] = $action;
     $formlet = $formlet->mapHTML(V::fn(function ($dict, $html) use($attrs) {
         return H::tag("form", $attrs, $html);
     }));
     $name_source = NameSource::instantiate($this->_id);
     $repr = $formlet->instantiate($name_source);
     $this->_builder = $repr["builder"];
     $this->_collector = $repr["collector"];
 }