[phplib] tpl_form From: Strange Alex (strange <email protected>)
Date: 05/25/00

Hello phplib,

  I found that isnt possible to use more then one forms (subclasses of
  tpl_form) at one page. Its because set_default_values() define
  GLOBAL variables, including form_name. Thats mean, when
  default_process() of first class is used, the submitted value is
  lost, and other forms dont works (cant pass general validate()).

  I suggest this solution:

  1) rename get_default_values() to get_submitted_values()
     that retrieve values from global variables
     
  2) let set_default_values() and get_default values work with
  $form->element->value values, not with global variables !

  Thats all! Use get_submitted_values() + set_default_values() in
  process_default() and get_default_values() if you jast want to print
  it (like in frozen elements).

  
  function get_submitted_values() {
    if (! is_object($this->form_data)) {
      $this->setup();
    }
    $fv = array();
    for (reset($this->form_data->elements); $elrec = current($this->form_data->elements); next($this->form_data->elements)) {
      $el = $elrec["ob"];
      $vn = $el->name;
      global $$vn;
      $fv[$el->name] = $$vn;
    }
    return $fv;
  }

  function set_default_values($fv) {
    if (! is_object($this->form_data)) {
      $this->setup();
    }
    if (! is_array($fv)) {
      return false;
    }
    $fv[form_name]= $this->classname;
    reset($fv);
    while (list($var, $value) = each($fv)) {
      $v = $this->form_data->elements[$var][ob];
      $v->value = $value;
      $this->form_data->elements[$var][ob]=$v;
    }
    return true;
  }

  function get_default_values() {
    if (! is_object($this->form_data)) {
      $this->setup();
    }
    $fv = array();
    for (reset($this->form_data->elements); $elrec = current($this->form_data->elements); next($this->form_data->elements)) {
      $el = $elrec["ob"];
      $fv["$el->name"] = "$el->value";
    }
    return $fv;
  }

С уважением, Алексей Русанов
Научно-производственное предприятие "Юникон Плюс", Новосибирск
Ведущий специалист отдела Internet технологий
Unix network administrator
Тел: +7 3832 23-94-06
         +7 3832 10-00-50
Факс: +7 3832 23-94-06
ICQ UIN: 8397628
URL: http://www.unicon.ru/
         http://www.H-ck.ru/

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>