2
Ich versuche, ein Formular über Config zu validieren. Wenn ich ein leeres Eingabefeld einreiche, wird nur die gleiche Seite angezeigt. Ich muss angezeigt Fehler in add_article.php Hilfe ....Validierungsregeln aus der Konfigurationsdatei setzt keine Fehler
config/form_validation.php
<?php
$config = [
'add_article_rules' => [
[
'field' => 'title',
'label' => 'Article Title',
'rules' => 'required|alphadash'
],
[
'field' => 'body',
'label' => 'Article Body',
'rules' => 'required'
]
]
];
Mein Controller (admin.php)
<?php
class Admin extends MY_Controller{
public function __construct(){
parent::__construct();
if(! $this->session->userdata('user_id')){
return redirect('login');
}
}
public function dashboard(){
$this->load->model('articlesmodel','articles');
$articles= $this->articles->article_list();
$this->load->view('admin/dashboard',['articles'=>$articles]);
}
public function add_article(){
$this->load->view('admin/add_article');
}
public function store_article(){
$this->load->library('form_validation');
if($this->form_validation->run('add_article_rules')){
//if sucesss
}else{
return redirect('admin/add_article');
}
}
public function edit_select(){}
public function edit_article(){}
public function delete_article(){}
}
anzeigen Datei (add_article. php)
<?php require_once('admin_header.php'); ?>
<div class="container">
<?php echo validation_errors(); ?>
<div class="row">
<?php echo form_open('admin/store_article',['class'=>'form-horizontal']); ?>
<?php echo form_hidden('user_id', $this->session->userdata('user_id'));?>
<fieldset>
<legend>Add Article</legend>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputEmail" class="col-lg-4 control-label">Title</label>
<div class="col-lg-8">
<?php
$data = array(
'name' => 'title',
'class' => 'form-control',
'value' => set_value('title'),
'placeholder' => 'Username'
);
echo form_input($data);
?>
</div>
</div>
</div>
<div class="col-sm-6">
<?php echo form_error('title'); ?>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputPassword" class="col-lg-4 control-label">Article Body</label>
<div class="col-lg-8">
<?php
$data = array(
'name' => 'body',
'value' => set_value('body'),
'class' => 'form-control',
'placeholder' => 'Article Body',
);
echo form_textarea($data);
?>
</div>
</div>
</div>
<div class="col-sm-6">
<?php echo form_error('body'); ?>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<div class="col-lg-8 col-lg-offset-4">
<?php
$data = array(
'name' => 'reset',
'class' => 'btn btn-default',
'value' => 'Reset',
);
echo form_reset($data);
?>
<?php
$data = array(
'name' => 'submit',
'class' => 'btn btn-primary',
'value' => 'Submit',
);
echo form_submit($data);
?>
</div>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
<?php require_once('admin_footer.php'); ?>