Assistance requested for help in restructuring my PHP class methods
<p>Hopefully somebody can help with this problem</p>

<p>My objective: to create a class that creates HTML forms.</p>

<pre><code>$cont-&gt;individual_fields("text", "feedName", "feed-name", null, "The name of the feed:", "200", "YES");
</code></pre>

<p>The above uses the individual_fields() method to add values for the various HTML attributes to be found in a text input field.</p>

<p>The method:</p>

<pre><code>public function individual_fields($type, $name, $id, $class = null, $desc, $maxlength = null, $value = null, $select = null) { }
</code></pre>

<p>Within the method I create a multidimensional array:</p>

<pre><code>    $fields_essentials = array(
        'type' =&gt; $type,
        'name' =&gt; $name,
        'id' =&gt; $id,
        'desc' =&gt; $desc,
        'class' =&gt; $class,
        'maxlength' =&gt; $maxlength,
        'value' =&gt; $value,
        'select' =&gt; $select);
</code></pre>

<p>So I now have a multidimensional array with attribute labels and values. Great.</p>

<p>Now I use a foreach to loop through array creating the HTML form field.</p>

<p>So it ends up with:</p>

<pre><code>$text = '&lt;tr&gt;';
$text .= "&lt;th&gt;&lt;label for=\"$id\"&gt;$desc&lt;/label&gt;&lt;/th&gt;";
$text .= '&lt;td&gt;&lt;'.$form.' &gt;&lt;/td&gt;';
$text .= '&lt;/tr&gt;';

return $text;
</code></pre>

<p>The HTML is as follows:</p>

<pre><code>&lt;label for="feed-name"&gt;The name of the feed:&lt;/label&gt;

&lt;input type="text" value="" maxlength="200" class="regular-text code " id="feed-name"name="affiliate_hoover_plugin_options[feedName]"/&gt;
</code></pre>

<p>All super smashing so far.</p>

<p>Now the problem I have is taking the returned results of the individual_fields() method and placing it into another method called create_form():</p>

<pre><code>echo $cont-&gt;create_form("post", "#action", "optionForm", "option-form", "multipart/form-data");

public function create_form($method, $action = null, $name = null, $id = null, $enctype = null) {

    extract($this-&gt;config_settings());

    $form = null;

    $form .= "&lt;form method=\"$method\" ";

    ($action !== null) ? $form .= " action=\"$action\"" : null;
    ($name !== null) ? $form .= " name=\"$name\"" : null;
    ($id !== null) ? $form .= " id=\"$id\"" : null;
    ($enctype !== null) ? $form .= " enctype=\"$enctype\"" : null;

    $form .= "&gt;";
    $form .= '&lt;fieldset&gt;';
    $form .= "&lt;legend&gt;$page_title&lt;/legend&gt;";

    $form .= '&lt;table class="form-table"&gt;';
    $form .= '&lt;tbody&gt;';

    $form .= '&lt;/tbody&gt;';
    $form .= '&lt;/table&gt;';
    // input fields here

    // INDIVIDUAL FIELDS FROM individual_fields() method here

    // permenant settings for every form
    $form .= $this-&gt;perm_fields();
    $form .= '&lt;input type="submit" id="submit" name="submitForm" class="button-primary" value="Save Changes"&gt;';
    $form .= '&lt;/fieldset&gt;';
    $form .= '&lt;/form&gt;';

    return $form;

}
</code></pre>

<p><strong>How do I save the returned values from the individual_fields() method and use it in the create_form() method?</strong></p>

<p>I've tried so many different approaches and spent a hell of a lot of time on this issue that I wonder if the problem lies in how I am structuring my class methods rather than an issue of scope.</p>

<p>If you have read this post from top to bottom, I thank you</p>

<p>Edit:</p>

<p>Reading the responses below and thinking about it a bit more I may just add the field details as any array to the create_form function so it looks like this:</p>

<pre><code>$cont-&gt;create_form("post", "#action", "optionForm", "option-form", "multipart/form-data", array("text", "feedName", "feed-name", null, "The name of the feed:", "200", "YES"), array("text", "urlName", "url-name", null, "The URL of the feed:", "300", "YES"));
</code></pre>

<p>It's a bit more of a complex lump of code that I wanted though. It would have been nice to be able to separate it.</p>
