[eluser]Mutsop[/eluser]
Hi,
For some reason I get Undefined property errors of my validations...
controller:
Code:
<?php
class Contact extends Controller {
function Contact(){
parent::Controller();
// load helper
$this->load->helper(array('form','url'));
$this->load->library('validation');
}
function Index(){
$data['attributes'] = array('class' => 'submit', 'type' => 'submit', 'name' => 'submit', 'value' => 'Verzenden');
$data['heading'] = 'Contact';
$this->load->view('header');
$this->load->view('navigation');
$this->load->view('contact', $data);
$this->load->view('footer');
}
function submit() {
$this->_set_fields();
$this->_set_rules();
if ($this->validation->run() == FALSE){
$data['message'] = '';
}else{
$data['message'] = 'Bericht succesvol gestuurd';
}
$data['heading'] = 'Contact';
$data['attributes'] = array('class' => 'submit', 'type' => 'submit', 'name' => 'submit', 'value' => 'Verzenden');
$this->load->view('header');
$this->load->view('navigation');
$this->load->view('contact', $data);
$this->load->view('footer');
}
function _set_fields(){
$fields['voornaam'] = 'voornaam';
$fields['email'] = 'email';
$fields['commentaar'] = 'commentaar';
$this->validation->set_fields($fields);
}
// validation rules
function _set_rules(){
$rules['voornaam'] = 'trim|required';
$rules['email'] = 'trim|required|valid_email';
$rules['commentaar'] = 'trim|required';
$this->validation->set_rules($rules);
$this->validation->set_message('required', '* verplicht');
$this->validation->set_message('isset', '* verplicht');
$this->validation->set_error_delimiters('<p class="error">', '</p>');
}
}?>
View:
Code:
<section id="content">
<div id="wrapper">
<div class="bg1 pad">
<h3><?php echo $heading; ?></h3>
<article class="col2">
<?php echo form_open('contact/submit'); ?>
<p>
<label for="voornaam">Voornaam / naam: </label>
<input type="text" name="voornaam" class="text" value="<?php echo $this->validation->voornaam; ?>"/>
<?php echo $this->validation->voornaam_error; ?>
</p>
<p>
<label for="email">E-mail: </label>
<input type="text" name="email" class="text" value="<?php echo $this->validation->email; ?>"/>
<?php echo $this->validation->email_error; ?>
</p>
<p>
<label for="commentaar">Commentaar: </label>
<textarea name="commentaar"><?php echo $this->validation->commentaar; ?></textarea>
<?php echo $this->validation->commentaar_error; ?>
</p>
<p>
<?php echo form_submit($attributes); ?>
</p>
<?php echo form_close(); ?>
</article>
<article class="col1">
</article>
</div>
</div>
</section>
So on each of my <?php echo $this->validation->xxxxx; ?> and _error I get the Undefined property error... As you can see, I do declare them trhough the rules and fields.
So why?