[eluser]CodeTroll[/eluser]
My goal is to use the same view/template for editing and creating a blog entry. I started out with form validation as per the documentation and that works fine when submitting the form.
My next step was to prepopulate the form with data from the database.
As can be seen from the 'blog_entry' => $this->blog_model->get_entry($blogid) the result array is one level lower than the other fields in $data. I guess that is the problem, but I am
not sure how to fix it..
I could get each field from the database array and add it manually to the $data array, but if an easier way exists I would appreciate it
Relevant database fields:
Sorry some of the text is in danish - but it should be understandable anyway (rediger=edit)
Snippet from controller:
Code:
function rediger($blogid) {
$site_title = $this->config->item('sb_site_title')."Blog - rediger";
$data = array ('site_title' => $site_title,
'local_menu' => $this->_get_local_menu(),
'blog_entry' => $this->blog_model->get_entry($blogid)
);
$this->parser->parse('blog/blog_rediger', $data);
}
Snippets from view/template blog_rediger.php
Code:
<?php echo validation_errors(); ?>
<?php echo form_open('blog/gem'); ?>
<input type="hidden" name="blogid" value="<?php echo set_value('blogid'); ?>" />
Titel<br />
<input type="text" name="titel" value="<?php echo set_value('titel'); ?>" size="80" maxlength="150"/>
<br />Tekst<br />
<textarea name="tekst" cols="80" rows="15"/><?php echo set_value('tekst'); ?></textarea>
<div><input type="submit" value="Gem indlæg" /></div>
</form>