[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><?php echo $header; ?> Form</legend>
<table>
<tr>
<td>Network id</td>
<td><input type="text" name="network_id" value="<?php echo set_value('network_id'); ?>" size="2" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('network_id'); ?></td></tr>
<tr>
<td>Affiliate id</td>
<td><input type="text" name="affiliate_id" value="<?php echo set_value('affiliate_id'); ?>" size="10" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('affiliate_id'); ?></td></tr>
<tr>
<td>Affiliate name</td>
<td><input type="text" name="affiliate_nme" value="<?php echo set_value('affiliate_nme'); ?>" size="75" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('affiliate_nme'); ?></td></tr>
<tr>
<td>Affiliate logo URL</td>
<td><input type="text" name="affiliate_logo_URL" value="<?php echo set_value('affiliate_logo_URL'); ?>" size="150" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('affiliate_logo_URL'); ?></td></tr>
<tr>
<td>Affiliate Link</td>
<td><input type="text" name="affiliate_link" value="<?php echo set_value('affiliate_link'); ?>" size="150" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('affiliate_link'); ?></td></tr>
<tr>
<td>Public Link</td>
<td><input type="text" name="public_link" value="<?php echo set_value('public_link'); ?>" size="150" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('public_link'); ?></td></tr>
<tr>
<td>Description</td>
<td><textarea name="desc_txt" value="<?php echo set_value('desc_txt'); ?>" rows="10" cols="100"</textarea></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('desc_txt'); ?></td></tr>
<tr>
<td>Active indicator</td>
<td><input type="text" name="status_cd" value="<?php echo set_value('status_cd'); ?>" size="1" /></td>
</tr>
<tr class="error"><td></td><td><?php echo form_error('status_cd'); ?></td></tr>
<tr>
<td></td><td><input type="submit" value="Submit" /></td>
</tr>
</table>
</fieldset>
</form>
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?