示例#1
0
 /**
  * @covers Xoops\Form\Select::render
  * @covers Xoops\Form\Select::renderOption
  * @covers Xoops\Form\Element::themeDecorateElement
  */
 public function testRender()
 {
     $this->object->addOptionArray(array('opt_key' => 'opt_name', 'opt_just_key' => null));
     $this->object->setValue('opt_key');
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<select'));
     $this->assertTrue(false !== strpos($value, 'name="name"'));
     $this->assertTrue(false !== strpos($value, 'size="1"'));
     $this->assertTrue(false !== strpos($value, 'title="Caption"'));
     $this->assertTrue(false !== strpos($value, 'id="name"'));
     $this->assertTrue(false !== strpos($value, '<option'));
     $this->assertTrue(false !== strpos($value, 'value="opt_key"'));
     $this->assertTrue(false !== strpos($value, '>opt_name</option>'));
     $this->assertTrue(false !== strpos($value, 'value="opt_just_key"'));
     $this->assertTrue(false !== strpos($value, '>opt_just_key</option>'));
     $this->object = new Select('Caption', 'name', 'value');
     // reset object
     $groups = array('grp_key' => 'grp_name', 'grp_key1' => 'grp_name1');
     $this->object->addOptionGroup('opt_grp_name', $groups);
     $value = $this->object->render();
     $this->assertTrue(is_string($value));
     $this->assertTrue(false !== strpos($value, '<select'));
     $this->assertTrue(false !== strpos($value, 'name="name"'));
     $this->assertTrue(false !== strpos($value, 'size="1"'));
     $this->assertTrue(false !== strpos($value, 'title="Caption"'));
     $this->assertTrue(false !== strpos($value, 'id="name"'));
     $this->assertTrue(false !== strpos($value, '<optgroup'));
     $this->assertTrue(false !== strpos($value, 'label="opt_grp_name"'));
     $this->assertTrue(false !== strpos($value, '<option'));
     $this->assertTrue(false !== strpos($value, 'value="grp_key"'));
     $this->assertTrue(false !== strpos($value, '>grp_name</option>'));
     $this->assertTrue(false !== strpos($value, 'value="grp_key1"'));
     $this->assertTrue(false !== strpos($value, '>grp_name1</option>'));
 }
示例#2
0
 private function createSelect($name, $options)
 {
     $select = new Select();
     $select->setLanguage($this->language);
     $select->push('name', $this->getName() . '[' . $name . ']');
     if ($this->value && $this->value[$name]) {
         $select->setValue($this->value[$name]);
     }
     $this->proxyPush($select);
     $this->buildOptions($select, $options);
     return $select;
 }
示例#3
0
 public function testGetHtmlJs()
 {
     $selectId = 'testId';
     $selectClass = 'testClass';
     $selectTitle = 'testTitle';
     $selectName = 'testName';
     $options = ['testValue' => 'testLabel', 'selectedValue' => 'selectedLabel'];
     $selectedValue = 'selectedValue';
     $this->select->setId($selectId);
     $this->select->setClass($selectClass);
     $this->select->setTitle($selectTitle);
     $this->select->setName($selectName);
     $this->select->setOptions($options);
     $this->select->setValue($selectedValue);
     $result = '<select name="testName" id="testId" class="testClass" title="testTitle" >' . '<option value="testValue" #{option_extra_attr_4016862802} >testLabel</option>' . '<option value="selectedValue" selected="selected" #{option_extra_attr_662265145} >selectedLabel</option>' . '</select>';
     $this->select->setIsRenderToJsTemplate(true);
     $this->assertEquals($result, $this->select->getHtml());
 }
  <head>
    <meta charset="utf-8">
    <title>Form Class</title>
  </head>
  <body>
    <form class="" action="task13.php" method="post">
        <input type="text" name="name" value="<?php 
echo isset($_POST['name']) ? $_POST['name'] : '';
?>
">
        <input type="text" name="username" value="<?php 
echo isset($_POST['username']) ? $_POST['username'] : '';
?>
">
        <input type="text" name="email" value="<?php 
echo isset($_POST['email']) ? $_POST['email'] : '';
?>
">
        <?php 
$select = new Select();
$select->setName('browser');
if (isset($browserTypes)) {
    $select->setValue($browserTypes);
    $select->makeSelect();
}
?>
        <input type="submit" name="submit" value="Submit">
    </form>
  </body>
</html>
$selectBrowser = new Select();
$selectBrowser->setName('browser');
echo '<p>Work Access</p>';
if (isset($browserTypes)) {
    $selectBrowser->setValue($browserTypes);
    $selectBrowser->makeSelect();
    unset($selectBrowser);
}
echo '<p>Connection Speed</p>';
$selectSpeed = new Select();
$selectSpeed->setName('speeds');
if (isset($speeds)) {
    $selectSpeed->setValue($speeds);
    $selectSpeed->makeSelect();
    unset($selectSpeed);
}
echo '<p>Operating System</p>';
$selectOs = new Select();
$selectOs->setName('os');
if (isset($os)) {
    $selectOs->setValue($os);
    $selectOs->makeSelect();
    unset($selectOs);
}
?>
          <input type="submit" name="submit" value="Submit">
      </form>
    </div>
  </body>
</html>
				<p>
				  Username:
				  <input type="text" name="username" size="60" />
				</p>
				<p>
				  Email:
				  <input type="text" name="email" size="60" />
				</p>
				<p>
				  Browser:
				  <?php 
    //Instantiate object
    $browser = new Select();
    //Set properties
    $browser->setName('browser');
    $browser->setValue($browsers);
    //The object has the data it needs from the preceding commands.
    //Tell it to make the select field.
    $browser->makeSelect();
    ?>
				</p>
				<p>
				  <input type="submit" name="submit" value="Go" />
				</p>
			</form>
			<?php 
    //If form submitted, process input.
} else {
    //Retrieve user responses.
    $name = $_POST['name'];
    $username = $_POST['username'];