/**
  * set up the form; do replacements, set up validation
  *
  * @return void
  * @author Andy Bennett
  */
 public function setup_form()
 {
     // set up an empty array to hold the row objects
     $this->rows = array();
     if (isset($this->form->append_data)) {
         foreach ($this->form->append_data as $n) {
             foreach ($n as $k => $v) {
                 Display::instance()->append_data($k, $v);
             }
         }
     }
     if (!isset($this->form->steamform_js) or $this->form->steamform_js == 'true') {
         // Display::instance()->add_javascript('/cache/js/steamform');
         Display::instance()->add_javascript('/steamform/index/steamform');
     }
     /*
     	<events>
     		<event>
     			<clear>true</clear>
     			<event>steamform_home_stories_edit.complete</event>
     			<class>adminform_helpers</class>
     			<method>event_home_stories_edit_complete</method>
     		</event>
     	</events>
     */
     if (isset($this->form->events)) {
         foreach ($this->form->events->event as $e) {
             if (!isset($e->class) or !isset($e->method) or !isset($e->event)) {
                 continue;
             }
             $c = (string) $e->class;
             $m = (string) $e->method;
             $ev = (string) $e->event;
             if (isset($e->clear) and (string) $e->clear == 'true') {
                 Event::clear($ev);
             }
             Event::add($ev, array($c, $m));
         }
     }
     // iterate through the form pages
     foreach ($this->form->pages->page as $page) {
         // set a temporary array to hold the row objects
         $temp_row = array();
         $n_row = 0;
         // iterate through the page rows
         foreach ($page->rows->row as $row) {
             // get the name of the row, and the post name
             $name = (string) $row->name;
             $fname = 'form_' . $name;
             // fix any dates
             steamform_helper::fix_dates($this->post, $row, $fname);
             // create an instance of the form row object
             $temp_row[] = new SteamFormRow($this, $row, $n_row);
             if ($row->type == 'colour') {
                 Display::instance()->append_data('jsfiles', '/cache/js/colour_picker');
             }
             if (isset($row->rules)) {
                 foreach ($row->rules->rule as $rule) {
                     $this->post->add_rules($fname, (string) $rule);
                 }
             }
             if (isset($row->filters)) {
                 foreach ($row->filters->filter as $filter) {
                     $this->post->pre_filter((string) $filter, $fname);
                 }
             }
             if (isset($row->callbacks)) {
                 foreach ($row->callbacks->callback as $callback) {
                     $this->post->add_callbacks($fname, array((string) $callback['class'], (string) $callback));
                 }
             }
             $n_row++;
         }
         $this->rows[] = $temp_row;
     }
 }