Hello Community,
i have a big problem with my Form. When i press the submit button, the insert into MYSQL function writes two entrys… not one Entry! So this Entry is duplicate in my database…
Please Help!!!!
I dont know why….
VIEW:
<?php
// Form erstellen
echo form_open('', 'id="entryForm"');
echo form_input('betreff', 'Betreff', 'id="betreff"');
echo form_textarea('content', 'Content', 'id="content"');;
echo form_submit('submit', 'Absenden', 'id="submit"');
echo form_close();
?>
// JAVASCRIPT
$('#submit').click(function() {
var form_data = {
betreff : $('#betreff').val(),
content : $('#content').val(),
ajax : '1'
};
$.ajax({
url: "<?php echo site_url('entry/doEntry'); ?>",
type: 'POST',
data: form_data,
success: function(msg) {
$('#write-entry').html(msg);
}
});
return false;
});
// END JAVASCRIPT
CONTROLLER:
<?php
class Entry extends CI_Controller{
public function doEntry(){
// Model laden
$this->load->model('entry_model');
// Wurde das Ajax Formular benutzt?
if ($this->input->post('ajax')) {
// Wenn Insert Erfolgreich
if($this->entry_model->insert()){
echo "SUCCESS!";
};
}
}
?>
MODEL:
<?php
class Entry_model extends CI_Model{
function insert(){
$data = array(
'headline' => $this->input->post('betreff'),
'content' => $this->input->post('content')
);
$insert = $this->db->insert('entry', $data);
return $insert;
}
}
?>