private function _replace_form_tags($template, $opening_tag, $closing_tag)
 {
     $Perch = Perch::fetch();
     $OpeningTag = new PerchXMLTag($opening_tag);
     if ($OpeningTag->prefix()) {
         if ($OpeningTag->prefix() == 'none') {
             $this->field_prefix = '';
         } else {
             $this->field_prefix = $OpeningTag->prefix() . '_';
         }
     } else {
         $Perch->form_count++;
         $this->field_prefix = 'form' . $Perch->form_count . '_';
     }
     $attrs = array();
     $attrs['id'] = $this->field_prefix . $OpeningTag->id();
     $attrs['class'] = $OpeningTag->class();
     $attrs['action'] = $OpeningTag->action();
     $attrs['method'] = $OpeningTag->method();
     $attrs['role'] = $OpeningTag->role();
     $attrs['name'] = $OpeningTag->name();
     $attrs['autocomplete'] = $OpeningTag->autocomplete();
     $aria = $OpeningTag->search_attributes_for('aria-');
     if (PerchUtil::count($aria)) {
         $attrs = array_merge($attrs, $aria);
     }
     $html5data = $OpeningTag->search_attributes_for('data-');
     if (PerchUtil::count($html5data)) {
         $attrs = array_merge($attrs, $html5data);
     }
     $this->form_id = $OpeningTag->id();
     $this->handling_app = $OpeningTag->app();
     $this->template_path = $OpeningTag->template();
     $this->action = $OpeningTag->action();
     $this->app = $OpeningTag->app();
     $this->method = $OpeningTag->method();
     if (PERCH_HTML5 && $OpeningTag->novalidate()) {
         $attrs['novalidate'] = 'novalidate';
     }
     if (PERCH_RUNWAY) {
         if (!$attrs['action']) {
             $Runway = PerchRunway::fetch();
             $attrs['action'] = $Runway->get_page();
         }
     } else {
         if (!$attrs['action']) {
             $attrs['action'] = $Perch->get_page_as_set(true);
         }
     }
     // submit via ssl?
     if (PERCH_SSL && $OpeningTag->ssl() && PerchUtil::bool_val($OpeningTag->ssl())) {
         $attrs['action'] = PerchUtil::url_to_ssl($attrs['action']);
     }
     if (!$attrs['method']) {
         $attrs['method'] = 'post';
     }
     $this->form_key = base64_encode($this->form_id . ':' . $this->handling_app . ':' . $this->template_path . ':' . time());
     // Does it have file fields?
     $s = '/(<perch:input[^>]*type="(file|image)"[^>]*>)/s';
     if (preg_match($s, $template)) {
         $attrs['enctype'] = 'multipart/form-data';
     }
     $new_opening_tag = PerchXMLTag::create('form', 'opening', $attrs);
     $template = str_replace($opening_tag, $new_opening_tag, $template);
     $new_closing_tag = PerchXMLTag::create('form', 'closing');
     $template = str_replace($closing_tag, $new_closing_tag, $template);
     return $template;
 }