Skip to content

Instantly share code, notes, and snippets.

@estefanionsantos
Created April 10, 2022 17:08
Show Gist options
  • Save estefanionsantos/74a712caef8b742e8da0d19363d466d1 to your computer and use it in GitHub Desktop.
Save estefanionsantos/74a712caef8b742e8da0d19363d466d1 to your computer and use it in GitHub Desktop.
select element
<?php
use Rubricate\Element\CreateElement;
use Rubricate\Element\StrElement;
$select = new CreateElement('select');
$select->setAttribute('name', 'latim');
$opt[] = 'lorem';
$opt[] = 'ipsum';
$opt[] = 'dolor';
foreach ($opt as $value => $text){
$option = new CreateElement('option');
$option->setAttribute('value', $value);
$option->addChild(new StrElement($text));
$select->addChild($option);
}
echo $select->getElement();
/*
<select name="latim">
<option value="0">lorem</option>
<option value="1">ipsum</option>
<option value="2">dolor</option>
</select>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment