Welcome Guest, Not a member yet? Register   Sign In
I just don't get it, I tell ya!!
#1

[eluser]cobolCowboy[/eluser]
I created an MVC setup that works great! Shows a form, POSTs the values then takes the data and inserts it to the database.

Now, I want to use the same form view to display the row for update purposes.

So I created an update function in the controller that successfully retrieves an array with the row in it based on $id, but I fail to understand how to pass that data to the view so that the values are pre-populated on the form.

The form view in embedded using a load into my template view by way of a content identifier that I pass to the template view. The view looks like this:

Code:
<?php echo form_open('advertisers/$action'); ?>
    
    <fieldset>
        <p class="red floatRight clearBoth">All fields are required. </p>
        <legend>&lt;?php echo $header; ?&gt; Form</legend>
            <table>
                <tr>
                    <td>Network id</td>
                    <td>&lt;input type="text" name="network_id" value="&lt;?php echo set_value('network_id'); ?&gt;" size="2" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('network_id'); ?&gt;</td></tr>
                <tr>
                    <td>Affiliate id</td>
                    <td>&lt;input type="text" name="affiliate_id" value="&lt;?php echo set_value('affiliate_id'); ?&gt;" size="10" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('affiliate_id'); ?&gt;</td></tr>
                <tr>
                    <td>Affiliate name</td>
                    <td>&lt;input type="text" name="affiliate_nme" value="&lt;?php echo set_value('affiliate_nme'); ?&gt;" size="75" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('affiliate_nme'); ?&gt;</td></tr>
                <tr>
                    <td>Affiliate logo URL</td>
                    <td>&lt;input type="text" name="affiliate_logo_URL" value="&lt;?php echo set_value('affiliate_logo_URL'); ?&gt;" size="150" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('affiliate_logo_URL'); ?&gt;</td></tr>
                <tr>
                    <td>Affiliate Link</td>
                    <td>&lt;input type="text" name="affiliate_link" value="&lt;?php echo set_value('affiliate_link'); ?&gt;" size="150" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('affiliate_link'); ?&gt;</td></tr>
                <tr>
                    <td>Public Link</td>
                    <td>&lt;input type="text" name="public_link" value="&lt;?php echo set_value('public_link'); ?&gt;" size="150" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('public_link'); ?&gt;</td></tr>
                <tr>
                    <td>Description</td>
                    <td>&lt;textarea name="desc_txt" value="&lt;?php echo set_value('desc_txt'); ?&gt;" rows="10" cols="100"&lt;/textarea></td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('desc_txt'); ?&gt;</td></tr>
                <tr>
                    <td>Active indicator</td>
                    <td>&lt;input type="text" name="status_cd" value="&lt;?php echo set_value('status_cd'); ?&gt;" size="1" /&gt;&lt;/td>
                </tr>
                <tr class="error"><td></td><td>&lt;?php echo form_error('status_cd'); ?&gt;</td></tr>
                <tr>
                    <td></td><td>&lt;input type="submit" value="Submit" /&gt;&lt;/td>
                </tr>
            </table>
    </fieldset>        
&lt;/form&gt;

them above view back loads the form when posting error messages.
So I created this the model function...
Code:
function getAdvsWhere($field,$param)
    {
        $this->db->where($field,$param);
        $query=$this->db->get('advertisers');
        return $query->result_array();
        
    }

The controller does this...
Code:
function Advertiser_Update($id)
    {
        $this->load->helper(array('form', 'url', 'html'));
        $this->load->model('Advertiser_model', 'advs');
        $row = $this->advs->getAdvsWhere('id', $id);
        $data = array (  'network_id'           => $row[0]['network_id']
                        ,'affiliate_id'         => $row[0]['affiliate_id']
                        ,'affiliate_nme'        => $row[0]['affiliate_nme']
                        ,'affiliate_logo_URL'   => $row[0]['affiliate_logo_URL']
                        ,'affiliate_link'       => $row[0]['affiliate_link']
                        ,'public_link'          => $row[0]['public_link']
                        ,'desc_txt'             => $row[0]['desc_txt']
                        ,'status_cd'            => $row[0]['status_cd']
                    );
        $data['title']      ='-----.com : Update Advertisers';
        $data['header']     ='Update Advertiser';
        $data['action']     ='update';
        $data['segment']    ='admin/';
        $data['viewname']   ='advertiser_form';
        $this->load->view('common/template',$data);
I tried this with a harcoded URI "advertiser_update/1", the $id=1, the result array is populated correctly, but I can't get the form to pre-populate. this doesn't work and I'm lost... and I don't know how to get the controller to somehow populate the fields being referenced in the view by the set_value functions, how, where?


Messages In This Thread
I just don't get it, I tell ya!! - by El Forum - 12-29-2009, 08:03 PM
I just don't get it, I tell ya!! - by El Forum - 12-29-2009, 09:19 PM
I just don't get it, I tell ya!! - by El Forum - 12-30-2009, 05:09 PM
I just don't get it, I tell ya!! - by El Forum - 12-30-2009, 05:32 PM
I just don't get it, I tell ya!! - by El Forum - 12-30-2009, 06:02 PM
I just don't get it, I tell ya!! - by El Forum - 12-30-2009, 06:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB