Hi everyboby,
My name is Dieter and I'm from Germany and new in this Forum here.
First I want to apologize for my bad english because this is my first post in english.
So now to my Problem.
I have a Form with some input fields to save it in a Database table. The Name of the Table is gaestebuch.
To check the input data I use the Form Validation Library. But when I submit the Form i get two lines with the follwing error Message.
Unable to access an error message corresponding to your field name.
I have testet the submit without the Form Validation. In this case the data will be sucessful saved in the database.
Here is my View: test_view.php
PHP Code:
<?php
echo validation_errors();
echo form_open('Test/save');
?>
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="80">Name:</td>
<td><input type="text" name="benutzername" size="50" maxlength="50"></td>
</tr>
<tr>
<td width="80">Email:</td>
<td><input type="text" name="email" size="50" maxlength="50"></td>
</tr>
<tr>
<td width="80">Web:</td>
<td><input type="text" name="web" size="50" maxlength="50"></td>
</tr>
<tr>
<td width="80">Nachricht:</td>
<td><textarea cols="50" rows="5" name="nachricht"></textarea></td>
</tr>
</table>
<br>
<input type="submit" name="speichern" value="Speichern">
</form>
This is the Model: Test_model.php
PHP Code:
<?php
class Test_model extends CI_Model {
public function __construct() {
$this->load->database();
}
/**
* @return
* @param
* @desc Abspeichern eines neuen Datensatzes
*/
function save() {
// Aktuelles Datumerstellen
$datum_save = date("d.m.y");
$data = array(
'aktiv' => '1',
'datum' => $datum_save,
'benutzername' => $this->input->post('benutzername'),
'email' => $this->input->post('email'),
'web' => $this->input->post('web'),
'nachricht' => $this->input->post('nachricht')
);
$this->db->insert('gaestebuch', $data);
$id = $this->db->insert_id();
}
}
And now here is the Controller: Test.php
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
/**
* @return
* @param
* @desc Laden des models
*/
public function __construct() {
parent::__construct();
$this->load->model('Test_model');
}
/**
* @return
* @param
* @desc Index Funktion des controllers
*/
public function index()
{
$this->load->view('header_view');
$this->load->view('test_view');
$this->load->view('footer_view');
}
/**
* @return
* @param
* @desc Funktion zu speichern eines Datensatzes
*/
public function save()
{
$this->load->library('form_validation');
// Eingabeüberprüfen der Inputfelder des Testformulares
$this->form_validation->set_rules('benutzername', 'Benutzername', 'required|xss_clean');
$this->form_validation->set_rules('nachricht', 'Nachricht', 'required|xss_clean');
// Wenn bei der Eingabe der Formularfelder Fehler auftreten zurück zum Formular
if($this->form_validation->run() === FALSE) {
$this->load->view('header_view');
$this->load->view('test_view');
$this->load->view('footer_view');
// Sonst weiter mit der Verarbeitung der Daten
} else {
$data["message"] = "Der Gästebucheintrag wurde erfolgreich gespeichert!";
$this->Test_model->save();
$this->load->view('header_view');
$this->load->view('success_view',$data);
$this->load->view('footer_view');
}
}
}
?>
I'm using Ubuntu with an XAMPP installed.
The PHP version is 5.5.19
The Mysql Version is 5.6.21
Codeigniter 3 dev.
In the autoload.php in the config folder I load the following helpers
$autoload['helper'] = array('url','form');
Is the there anybody who can help me?
Many thanks in advance.
Best regards
Dieter