If I was to use return instead of echo then I would get is null:
PHP Code:
var_dump($cont->individual_fields("text", "feedName", "feed-name", null, "The name of the feed:", "200", "YES"));
<pre xmlns="http://www.w3.org/1999/xhtml" dir="ltr" class="xdebug-var-dump"><font color="#3465a4">null</font>
</pre>
Using echo returns the HTML
There is clearly something fundamentally stupidly wrong with how I am looping through the values
Damn it
This is the first method:
PHP Code:
public function individual_fields($type, $name, $id, $class = null, $desc, $maxlength = null, $value = null,
$select = null) {
// validation remved
// create an array out of the parameter values
$fields_essentials = array(
'type' => $type,
'name' => $name,
'id' => $id,
'desc' => $desc,
'class' => $class,
'maxlength' => $maxlength,
'value' => $value,
'select' => $select);
// call the create_fields() methods
$this->create_fields($fields_essentials);
}
Which then passes the array to the second method which creates the individual HTML fields
PHP Code:
private function create_fields($fields_essentials) {
extract($this->config_settings());
foreach ($fields_essentials as $key => $value) {
if ($key === "type") {
switch ($value) {
case 'text':
// text area
$form = 'input type="text" ';
foreach ($fields_essentials as $key => $value) {
if ($key === "name") {
$form .= " name=\"{$option_name}[{$value}]\" ";
$name = $value;
}
if ($key === "id") {
($value !== null) ? $form .= " id=\"{$value}\" " : null;
$id = $value;
}
if ($key === "desc") {
$desc = $value;
}
if ($key === "class") {
if ($value !== null) {
$form .= " class=\"regular-text code {$value}\" ";
} else {
$form .= " class=\"regular-text code \" ";
}
}
if ($key === "maxlength") {
($value !== null) ? $form .= " maxlength=\"{$value}\" " : null;
}
if ($key === "value") {
if ($value !== null && $value != "YES") {
$form .= " value=\"{$value}\" ";
}
if ($value == "YES") {
$form .= ' value="';
$form .= isset($_POST[$option_name[$name]]) ? print $_POST[$option_name[$name]] : null;
$form .= '"';
}
} // end if $key
} // end foreach
$input = '<tr>';
$input .= "<th><label for=\"$id\">$desc</label></th>";
$input .= '<td><'.$form.' ></td>';
$input .= '</tr>';
return $input; break;
// I'M THE RETURN VALUE DO SOMETHING WITH ME!
case 'hidden':
case 'button':
case 'image':
case 'password':
case 'reset':
case 'submit':
// error here - there form inputs are not cattered for
die("You cannot use the individual_fields() method to create inputs for $key");
break;
default:
// error message here
die("Make sure the input type in the individual_fields() method is correct");
break;
} // end switch statement
} // end fi
} // end foreach
}
Bookmarks