Display the correct input type for the config option.
I am keying the input type off of the 'Hint' and 'Type' columns in the Config table. It would be easier if I just added an 'inputtype' column to the Config table, and I might do that later, but I don't want to mess with the database right now.
This commit is contained in:
parent
fe5df3eb8c
commit
bffe78904f
|
@ -18,9 +18,46 @@ foreach ($options as $option => $value) {
|
|||
echo "<div id=\"tabs-$option\">";
|
||||
foreach ($value as $val) {
|
||||
$id = $val['Config']['Id'];
|
||||
$inputname = 'Config.' . $id . '.' . $val['Config']['Name'];
|
||||
$name = $val['Config']['Name'];
|
||||
$inputname = 'Config.' . $id . '.' . $name;
|
||||
$type = $val['Config']['Type'];
|
||||
$hint = $val['Config']['Hint'];
|
||||
$hints = explode('|', $hint);
|
||||
$selectoptions = array();
|
||||
|
||||
switch ($val['Config']['Type']) {
|
||||
// Because I don't want to modify the database, I need
|
||||
// to work with what is already there to determine
|
||||
// which types of inputs to use. I can do this based
|
||||
// off of hthe 'hint' fileld.
|
||||
//
|
||||
// If 'hint' contains '|', it is either a radio
|
||||
// or select box, though I'm making all radios selects.
|
||||
// If the 'hint' contains '|' && '=', it was supposed to be a
|
||||
// select.
|
||||
//
|
||||
// This would be much easier if each Config row had an 'inputtype' column...
|
||||
|
||||
// If the type is supposed to be a radio...
|
||||
// I'm making it a select anyway!
|
||||
if (preg_match("/\|/", $hint) && ($type != 'boolean') ) {
|
||||
$type = 'select';
|
||||
foreach ($hints as $hint) {
|
||||
$foo = explode('|', $hint);
|
||||
$selectoptions[$foo[0]] = $foo[0]; // I don't want my selects indexed - I want them associated.
|
||||
}
|
||||
}
|
||||
|
||||
// If the type is supposed to be a select box...
|
||||
if ( preg_match("/\=/", $hint) && ($type == 'select') ) {
|
||||
$selectoptions = array();
|
||||
foreach ($hints as $hint) {
|
||||
$foo = explode('=', $hint);
|
||||
$selectoptions[$foo[1]] = $foo[0];
|
||||
}
|
||||
}
|
||||
|
||||
// For all of the other types, set them appropriately.
|
||||
switch ($type) {
|
||||
case 'boolean':
|
||||
$type = 'checkbox';
|
||||
break;
|
||||
|
@ -30,14 +67,22 @@ foreach ($options as $option => $value) {
|
|||
case 'string':
|
||||
$type = 'text';
|
||||
break;
|
||||
case 'text':
|
||||
$type = 'textarea';
|
||||
break;
|
||||
}
|
||||
|
||||
// Create the actual inputs. 'options' and 'legend'
|
||||
// are ignored when they're not needed, such as in
|
||||
// the case of a text or checkbox input type.
|
||||
echo $this->Form->input($inputname, array(
|
||||
'default' => $val['Config']['Value'],
|
||||
'label' => $val['Config']['Name'],
|
||||
'label' => $name,
|
||||
'title' => $val['Config']['Prompt'],
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
'options' => $selectoptions, // Only used by cakephp when 'type' is 'select'
|
||||
'legend' => false
|
||||
));
|
||||
echo "\n";
|
||||
}
|
||||
echo "</div>"; // End each category div
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue