HTML_QuickForm_Controller & DB & Smarty

From: Date: Tue, 27 Jul 2004 15:34:10 +0000
Subject: HTML_QuickForm_Controller & DB & Smarty
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13875@lists.php.net to get a copy of this message
Hello, I'm currently building a multi-language form using Gettext for the translations and Smarty to assign the strings. I'm also using PEAR::DB in order to retrieve some informations from a DB and fill a form (eg. a <select></select> tag with many <options></options> tag). How can I build a form without using global variables for the database and template engines ? Below is a simple example: /* ############################################# */ class Page_Add_Company extends HTML_QuickForm_Page { function buildForm()
    {
      global $db, $tpl;
      $this->_formBuilt = TRUE;
      // Retrieve contact list from the DB
      $query = 'SELECT c.contact_id, c.contact_name
                FROM '.CONTACT_TABLE.' c';
      $res =& $db->query($query);
      if (DB::isError($res))
         die($res->getMessage());
      $contact = array();
      while ($row =& $res->fetchRow()) {
        $contact[$row['contact_id']] = $row['contact_name'];
      }
      $company_contact_attr = array('multiple' => 'multiple',
                                    'size' => 5);
      $this->addElement('select',
                        'company_contact',
                        _('Select your contacts'),
                        $contact,
                        $company_contact_attr);
      // Assign a multi-lingual string through Smarty
      $tpl->assign('add_contact_lnk', _('Add a contact ?'));
      $this->addElement('submit', 'submit', _('Soumettre'));
      $this->setDefaultAction('submit');
    }
} /* ############################################# */ Thanks, -- Helix

« previous php.pear.general (#13875) next »