Fetching form results

In this section I will explain how to retrieve values from the form. This values may be stored in database, or they may go through validation checking. I will keep on extending on the previous example, so we introduce concepts bit by bit, the code added is emphasised.

Form values can be read with the method getValue of the class db_form, they also can be read with $_POST[] php variable, but some of them are more confortably fetched by the method because of added fancy processing. This is true for dates and checkboxes

An example output, echo are used here for testing purposes. Normally echo are not used inside Obliquid because any result is assigned to Smarty templates, but they are a convenient way to test something fast.

test | test
meaningless words | meaningless words
2002-04-26 | dateinput
Nick | Nick
0 |
beta | beta
  
  $dbf =& new db_form();
  
  if ($_POST["action"]=="exampleform") {
      //we are here, so the form was posted
      $dbf->parseForm(); //parse the form and reassign it back to controls
      //any variable can be accessed with $dbf->getValue()
      echo $dbf->getValue("name")." | ".$_POST["name"]."<br>";
      echo $dbf->getValue("description")." | ".$_POST["description"]."<br>";
      echo $dbf->getValue("moddate")." | ".$_POST["moddate"]."<br>";
      echo $dbf->getValue("author")." | ".$_POST["author"]."<br>";
      echo $dbf->getValue("enable")." | ".$_POST["enable"]."<br>";
      echo $dbf->getValue("version")." | ".$_POST["version"]."<br>";
  }
  
  $frm["name"]=$dbf->getTextInput("name",
      array("CLASS" => "textform", "SIZE" => "25"));
  $frm["description"]=$dbf->getTextArea("description",
      array("CLASS" => "textform", "ROWS" => "3", "COLS" => "45"));
  $frm["moddate"]=$dbf->getDateInput("moddate", 1998, date("Y")+2,
      array("CLASS" => "textform"));
  //radio buttons must start with a default, for the html specification
  $frm["author_no"]=$dbf->getRadio("author", "");
  $frm["author_st"]=$dbf->getRadio("author", "Stefano");
  $frm["author_ni"]=$dbf->getRadio("author", "Nick");
  $frm["enable"]=$dbf->getCheckbox("enable");
  $frm["version"]=$dbf->getSelect("version", array(array("1.0", "stable"),
      array("beta", "beta"),
      array("alpha", "alpha")
    ));
  $frm["submit"]=$dbf->getSubmit("submit", _l("Save"), array("CLASS" => "textform"))
      .$dbf->getHidden("action", "exampleform");

  $_obweb->smslot->assign(array("frm" => $frm));