我正在使用笨下面的代碼,並獲得錯誤form_validation,因爲form_validation不是running.Please幫我理清控制器的problem.The代碼:錯誤與笨
public function event_desc()
{
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('event_title','Event Title','required|max_length[40]');
$this->form_validation->set_rules('event_desc','Event Description','required');
$this->form_validation->set_rules('event_cat','Event Category','required|callback_is_default');
$this->form_validation->set_rules('event_date','Event Date','required|date');
$this->form_validation->set_rules('event_venue','Event Venue','required||max_length[25]');
$this->form_validation->set_rules('event_charges','Event Charges','required');
if($this->form_validation->run()== FALSE)
{
echo "error";
$this->is_logged_in();
}
else
{
echo "success";
$userId = $this->ion_auth->get_user_id();
$data=array(
'cat_id '=> $this->input->post('event_cat'),
'user_id' => $userId,
'event_title' => $this->input->post('event_title'),
'event_desc' => $this->input->post('event_desc'),
'event_date' => $this->input->post('event_date'),
'event_venue' => $this->input->post('event_venue'),
'event_charges' => $this->input->post('event_charges'),
);
$this->load->model('event_model');
$this->event_model->add_event_record($data);
$this->index();
}
}
public function _is_default($str)
{
if ($str != 'yes' && $str != 'no')
{
$this->form_validation->set_message('_check_select_yes_or_no', 'Please select yes or no for the %s field');
return FALSE;
}
else
{
return TRUE;
}
}
當我插入數據,並提交頁面顯示「錯誤」,因爲我已經回聲「錯誤」,如果form_validation()運行是false。 和我的視圖代碼:
<?php echo form_open('profile/event_desc'); ?>
<div class="event_wrapper">
<div class="label_content">
<div class="event_details">Event Title</div>
<input type="text" name="event_title" id="event_title" />
<?php echo form_error('event_title','<div class="error_event">','</div>');?>
</div><!-- end of label_content-->
<div class="label_content">
<div class="event_details">Event Description</div>
<textarea name="event_desc" id="event_desc"></textarea>
<?php echo form_error('event_desc','<div class="error_event">','</div>')?>
</div><!-- end of label_content-->
<div class="label_content">
<div class="event_details"> Event Category</div>
<select name="event_cat" id="eventcat">
<option value="select">_Select one_</option>
<option value="1">Informational Technology</option>
<option value="2">Education</option>
<option value="3">Entertainment</option>
<option value="4">Sports</option>
<option value="5">Seminars</option>
<option value="6">Research</option>
<option value="7">Science</option>
</select>
<?php echo form_error('event_cat','<div class="error_event">','</div>')?>
</div><!-- end of label_content-->
<div class="label_content">
<div class="event_details"> Event Date</div>
<input type="datetime" name="event_date" value="" id="event_title"/>
<?php echo form_error('event_date','<div class="error_event">','</div>')?>
</div>
<div class="label_content">
<div class="event_details"> Event Venue</div>
<input type="datetime" name="event_venue" value="" id="event_title"/>
<?php echo form_error('event_venue','<div class="error_event">','</div>')?>
</div>
<div class="label_content">
<div class="event_details"> Event Charges</div>
<input type="datetime" name="event_charges" value="" id="event_title"/>
<?php echo form_error('event_charges','<div class="error_event">','</div>')?>
</div>
<div class="label_content">
<div class="submit_gap">
<button type="submit" class="signin">Upload</button>
</div>
請幫我理清錯誤。