Welcome Guest, Not a member yet? Register   Sign In
dealing with multiple versions of one field in a form
#3

[eluser]jedd[/eluser]
Okay .. I want any number of forms to be displayed on this page. My view is a loop that goes through the form array data, which is set in the controller. I'll rip out logic regarding success/fail on validation etc as that doesn't seem appropriate here.

First, the view code. There's a little bit of HTML preamble here, and then straight into the loop. I suspect there's a better way of assigning the 'name' and 'value' bits within hidden() or submit() calls.
Code:
foreach ($search_form_data as $form)  {
    echo form_open ($form["target"]);
    echo $form["preamble"] . "     ";
    foreach ($form["input"] as $input_preamble=>$input_data)  {
        echo $input_preamble . " : ";
        echo form_input ($input_data);
        echo "       ";
        }
    echo form_hidden ($form["hidden"]["name"], $form["hidden"]["value"]);
    echo form_submit($form["submit"]["name"], $form["submit"]["button"]);
    echo form_close ();
    echo "<hr>";
    }


The code in the controller to generate the array. I have this being loaded via a call to a private function but you could do it within your search method if you preferred. I also needed a way of having multiple text boxes within each form. Note that I haven't got any facility for other types of form elements (radios, etc) .. but will implement that stuff when I need it. I expect it will fit into this structure reasonably well.

Oh, and people that know what they're doing -- be gentle when you read this.

Code:
$search_form_data = array (
            array (
                "preamble" => "Search on scientific name",            // This determines the form preamble
                "target"   => "organism/search",                    // Goes into form_open()
                "input"    => array (                            // Multiple form_input() in a single form
                    "Genus" => array (                        // Preamble for text box
                        'name'  => 'search_genus',                // form_input takes 'name' and 'value'
                        'value' => $posted_values['value_search_genus'],
                        ),
                    "Species" => array (
                        'name'  => 'search_species',
                        'value' => $posted_values['value_search_species'],
                        ),
                    ),
                "hidden" => array (                            // All forms are identified by hidden()
                    "name"  => "search_type",
                    "value" => "sci",
                    ),
                "submit" => array (                            // Submit button and name
                    "button" => "Go looking!",
                    "name"   => "submit_sci",
                    ),
                 ),
             // Obviously this stuff is repeated for extra forms
             );

Hmmm .. the forum has munged my tabs. Oh well.


Messages In This Thread
dealing with multiple versions of one field in a form - by El Forum - 03-10-2009, 08:35 PM
dealing with multiple versions of one field in a form - by El Forum - 03-10-2009, 09:00 PM
dealing with multiple versions of one field in a form - by El Forum - 03-10-2009, 09:10 PM
dealing with multiple versions of one field in a form - by El Forum - 03-10-2009, 09:41 PM
dealing with multiple versions of one field in a form - by El Forum - 03-11-2009, 01:53 AM
dealing with multiple versions of one field in a form - by El Forum - 03-11-2009, 03:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB