コード例 #1
0
ファイル: FormTagLib.php プロジェクト: hofmeister/Pimple
 /**
  * Render form tags
  * @param boolean binary | if set - renders a multipart form - else a url encoded form.
  * @param string controller | if set - sets the controller of the target url for this form
  * @param string action | if set - sets the action of the target url for this form
  * @param string parms | if set - sets the parameters of the target url for this form
  * @param array|object|json data | A map of data for this form - will be propegated to fields within this form.
  * @param string method | sets the HTTP method to used (post or get) - defaults to post
  * @param string url | sets the url of the form - only used if controller is not set
  * @param string id | sets the id on the form element
  * @param string class | sets the css class for the form element
  */
 protected function tagForm($attrs, $view)
 {
     if ($attrs->binary) {
         $attrs->enctype = 'multipart/form-data';
     } else {
         $attrs->enctype = 'application/x-www-form-urlencoded ';
     }
     if (!$attrs->controller && !$attrs->action && !$attrs->parms) {
         if (!$attrs->controller) {
             $attrs->controller = Pimple::instance()->getController();
             if (!$attrs->action) {
                 $attrs->action = Pimple::instance()->getAction();
             }
         }
         $attrs->url = Url::makeLink($attrs->controller, $attrs->action, $_SERVER['QUERY_STRING']);
     } else {
         if ($attrs->action && $attrs->controller) {
             $attrs->url = Url::makeLink($attrs->controller, $attrs->action, $attrs->parms);
         }
     }
     unset($attrs->binary);
     if ($attrs->data) {
         $this->formData = $this->toObject($attrs->data);
     } else {
         $this->formData = $view->data;
     }
     $attrs->method = strtolower($attrs->method ? $attrs->method : 'post');
     $this->formMethod = $attrs->method;
     $elm = new HtmlElement('form');
     $elm->setAttribute('method', $attrs->method);
     $elm->setAttribute('enctype', $attrs->enctype);
     $elm->setAttribute('action', $attrs->url);
     if ($attrs->id) {
         $elm->setAttribute('id', $attrs->id);
     }
     if ($attrs->class) {
         $elm->setAttribute('class', $attrs->class);
     }
     $elm->addChild(new HtmlText($this->body()));
     return $elm->toHtml();
 }