Welcome Guest, Not a member yet? Register   Sign In
How do you build a form with multiple database entries?
#1

[eluser]dallen33[/eluser]
So here's my code:
Code:
<?php

    $name = array(
        'name'    => 'name',
        'id'    => 'name',
        'size'    => 10,
        'value' => set_value('name')
    );

    $short_name = array(
        'name'    => 'short_name',
        'id'    => 'short_name',
        'size'    => 10
    );

    $width = array(
        'name'    => 'width',
        'id'    => 'width',
        'size'    => 10
    );

    $height = array(
        'name'    => 'height',
        'id'    => 'height',
        'size'    => 10
    );

    $exp_width = array(
        'name'    => 'exp_width',
        'id'    => 'exp_width',
        'size'    => 10
    );

    $exp_height = array(
        'name'    => 'exp_height',
        'id'    => 'exp_height',
        'size'    => 10
    );

    $expanding = array(
        'FALSE'  => 'Non-Expanding',
        'TRUE'    => 'Expanding'
    );
?>

<p>

&lt;?php echo anchor($this->dx_auth->logout_uri, $this->lang->line('common_logout'));?&gt;</p>
&lt;?php echo $this->dx_auth->get_username();?&gt;
&lt;?php echo $this->dx_auth->get_firstname();?&gt; &lt;?php echo $this->dx_auth->get_lastname();?&gt;

&lt;?php
    echo form_open($this->uri->uri_string());
    
    if ($adsizes_query->num_rows() > 0):
    foreach($adsizes_query->result() as $adsizes_row):

    // Find whether ad is expanding or isn't
    if ($adsizes_row->expanding === "TRUE"):
        $is_expanding = "TRUE";
    elseif ($adsizes_row->expanding === "FALSE"):
        $is_expanding = "FALSE";
    endif;
?&gt;

<p>

&lt;?php echo $adsizes_row->name;?&gt;

&lt;?php echo form_input($short_name, set_value($short_name['name'], $adsizes_row->short_name));?&gt;
&lt;?php echo form_error($short_name['name']);?&gt;

&lt;?php echo form_input($width, set_value($width['name'], $adsizes_row->width));?&gt;
&lt;?php echo form_error($width['name']);?&gt;

&lt;?php echo form_input($height, set_value($height['name'], $adsizes_row->height));?&gt;
&lt;?php echo form_error($height['name']);?&gt;

&lt;?php
    if ($is_expanding === "TRUE"):
        echo form_input($exp_width, set_value($exp_width['name'], $adsizes_row->exp_width));
        echo form_error($exp_width['name']);
        
        echo form_input($exp_height, set_value($exp_height['name'], $adsizes_row->exp_height));
        echo form_error($exp_height['name']);
    endif;
?&gt;

&lt;?php echo form_dropdown('expanding', $expanding, $is_expanding);?&gt;
&lt;?php echo $adsizes_row->proof_bg;?&gt;

</p>

&lt;?php
    endforeach;
    endif;
    
    echo form_close();
?&gt;
It basically shows rows of ad sizes with names, type, bg, etc. Instead of having a "Submit" button on each row, I'd like just one submit button on the bottom. So how do I differentiate between every input name/id? What's the best way of doing this?

I was thinking of somehow incrementing a number for the name/id, but not too sure how to do that, or even if it's the best way of doing it. Any help would be appreciated!
#2

[eluser]gullah[/eluser]
All of your inputs should have unique names so in your controller you will access the data using $this->input->post('fieldname', TRUE); This will allow you to access each individual form field.




Theme © iAndrew 2016 - Forum software by © MyBB