/** * method to create an HTML form based on the table schema * * The method creates an HTML table of input fields, and takes account * of several options, including the possibility to use checkbox fields * for one-to-many relationships, radio flieds for many-to-one relationships, * and boolean fields. * * @param string action that must be triggered by the form update or insert * @param array the default values of the form fields * @return string a string containing the HTML form * @throws none */ public function form($action, $data) { // Create the form object $form = new Zmax_HTML_Form("post", $this->url, false); $form->setTitle($this->title); // Put the hidden fields foreach ($this->hidden_fields as $nom => $value) { $form->champCache($nom, $value); } $form->champCache(self::ZMAX_EDIT_ACTION, $action); // Put also as hidden fields the values of the table form fields $form->champCache("show_table_form", $this->show_table_form); if ($this->show_table_form) { if (is_array($this->table_form_values)) { foreach ($this->table_form_values as $name => $value) { $form->champCache($name, $value); } } } // Put the primary key in a hidden field, to prevent // any possible change of the key foreach ($this->info['primary'] as $name) { if (isset($data[$name])) { $form->champCache("opk[{$name}]", $data[$name]); } } // Start a table, with 2 cols [Label | Field ] $form->debutTable(VERTICAL, array("width" => "80%"), 1, $this->title); // For each attribute, create a form field foreach ($this->info['cols'] as $name) { // Get the metadata on the field $meta = $this->info['metadata'][$name]; // Do not show hidden fields if (in_array($name, array_keys($this->hidden_fields))) { continue; } // Check that the default value exists if (!isset($data[$name])) { $data[$name] = ""; } $this->addFormField($form, $action, $name, $data[$name], $meta); } // Check the many-to-many associations foreach ($this->add_form_fields as $name => $bridge) { // Check whether there is a default value if (!isset($data[$name])) { $data[$name] = ""; } $html_field_name = "{$name}" . "[]"; $this->addFormField($form, $action, $name, $data[$name], array("DATA_TYPE" => "", "LENGTH" => "", "PRIMARY" => false), $html_field_name); } // OK. Now add lines for the slave table, if any if (!empty($this->slave_table)) { $form->debutTable(HORIZONTAL, array(), $this->size_slave_table); // Create a field for each attribute foreach ($this->slave_info['cols'] as $nom) { // Check that the default value exists if (!isset($data[$this->slave_table][$nom])) { $valeur = ""; } else { $valeur = $data[$this->slave_table][$nom]; } // Manage foreign keys if (isset($this->foreign_keys[$nom])) { $this->slave_info['metadata'][$nom]['FOREIGN'] = 1; if ($action == MAJ_BD) { $valeur = $data[$this->foreign_keys[$nom]]; } } $html_field_name = "{$this->slave_table}[{$nom}][]"; $this->addFormField($form, $action, $nom, $valeur, $this->slave_info['metadata'][$nom], $html_field_name); } $form->finTable(); } $form->finTable(); if ($action == self::DB_UPDATE) { $form->champValider($this->texts->form->modify, "submit"); } else { $form->champValider($this->texts->form->insert, "submit"); } return $form->formulaireHTML(); }
/** * Static method that returns a login form * */ public static function loginForm($req_controller, $req_action, $request) { // Get the current action URL (use the config to obtain the base URL) // Get the utilitary objects from the registry $registry = Zend_registry::getInstance(); $zmax_context = $registry->get("zmax_context"); $module_name = $request->getModuleName(); if (!empty($module_name)) { $module = $request->getModuleName() . "/"; } else { $module = ""; } $url = $zmax_context->config->app->base_url . "/" . $module . $request->getControllerName() . "/" . $request->getActionName() . "?1=1"; // The form always refers to the current controller // and to the current action $current_action = $request->getActionName(); $form = new Zmax_HTML_Form($url); $form->champCache("zmax_req_controller", $req_controller); $form->champCache("zmax_req_action", $req_action); $form->debutTable(); $form->champTexte($zmax_context->texts->zmax->login, "zmax_login", "", 20); $form->champMotDePasse($zmax_context->texts->zmax->password, "zmax_password", "", 20); $form->champValider($zmax_context->texts->zmax->submit, "submit_login"); $form->finTable(); return $form->fin(); }