dmBridge PHP API
DMTextField.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00015 class DMTextField extends DMAbstractFormField implements DMFormField {
00016 
00018    private $size;
00019 
00023    public final function getSize() {
00024       return $this->size;
00025    }
00026 
00030    public final function setSize($int) {
00031       $this->size = (int) $int;
00032    }
00033 
00038    public function getHTMLTag() {
00039       $dxml = new DMDOMDocument("1.0", "utf-8");
00040       $dxml->loadXML("<div/>");
00041 
00042       $class = "dmFormField";
00043       if (!$this->isValid() && $this->isUserData()) {
00044          $msg = $this->getValidationMessage();
00045          $dxml->documentElement->appendChild($dxml->createTextNode($msg));
00046          $dxml->documentElement->appendChild($dxml->createElement('br'));
00047          $class .= " dmInvalid";
00048       }
00049       $dxml->documentElement->setAttribute("class", $class);
00050 
00051       $input = $dxml->createElement("input");
00052       $input->setAttribute("type", "text");
00053       $input->setAttribute("name", $this->getHTMLName());
00054       $input->setAttribute("value", $this->getValue());
00055 
00056       if ($this->getSize()) {
00057          $input->setAttribute("size", $this->getSize());
00058       }
00059       if ($this->getMaxLength()) {
00060          $input->setAttribute("maxlength", $this->getMaxLength());
00061       }
00062       else if ($this->getMax()) {
00063          $input->setAttribute("maxlength", strlen($this->getMax()));
00064       }
00065       if (!$this->isEnabled()) {
00066          $input->setAttribute("disabled", "disabled");
00067       }
00068       foreach ($this->getAttributes() as $k => $v) {
00069          $input->setAttribute($k, $v);
00070       }
00071       $dxml->documentElement->appendChild($input);
00072 
00073       return $dxml->saveHTML($dxml->documentElement);
00074    }
00075 
00076 }
00077 
 All Data Structures Functions Variables