[eluser]felixk[/eluser]
Hi!
I've got a problem with my form validation, it always returns error, but no error displayed on the view. Here's the code:
Controller
Code:
// I include the necessary helpers and librarys in my autoload-file...
function Add_Comment()
{
//Formulärregler
$this->form_validation->set_rules('author', 'Namn', 'required|min_length[2]|max_length[40]|htmlspecialchars');
$this->form_validation->set_rules('mail', 'E-post', '|required|valid_email|htmlspecialchars');
$this->form_validation->set_rules('url', 'Hemsida', 'htmlspecialchars');
$this->form_validation->set_rules('comment', 'Kommentar', 'required|min_length[2]|htmlspecialchars');
//Om error
if ($this->form_validation->run() == FALSE)
{
redirect('blogg/id/'.$this->input->post('id'));
}
//Om inget error
else
{
$query = array
(
'blogg_id' => ($this->input->post('id')),
'name' => ($this->input->post('author')),
'url' => ($this->input->post('url')),
'mail' => ($this->input->post('mail')),
'text' => ($this->input->post('comment')),
'date' => date('Y-m-d, H:i'),
);
$this->blogModel->Add_Comment($query);
redirect('blogg/id/'.$this->input->post('id'));
} //Slut på "Om inget error (för formuläret)
}
The viewer:
Code:
<?php echo validation_errors(); ?>
<form action="<?php echo base_url(); ?>blogg/Add_Comment/<?php echo $row->id; ?>" method="post" id="commentform">
<p><input type="text" name="author" id="author" value="" tabindex="1" style="margin-right:10px;" /><label for="author">Namn *</label></p>
<p><input type="text" name="email" id="email" value="" tabindex="2" style="margin-right:10px;" /><label for="email">E-post *</label></p>
<p><input type="text" name="url" id="url" value="" tabindex="3" style="margin-right:10px;" /><label for="url">Webbplats</label></p>
<p class="comment_box">
<textarea name="comment" id="comment" tabindex="4" cols="40" rows="8"></textarea>
</p>
<p>
<input name="submit" class="form_submit" type="submit" id="submit" tabindex="5" value="Skicka" />
<input type="hidden" name="id" value="<?php echo $row->id; ?>" id="id" />
</p>
</form>
</div>
There is some foreach-loops before the form, but that's irrelevant for now.
Any ideas?
//Felix Karlsson