I have a form; I am using jQuery to post this form, but now I wonder how I can "reset" the form when I posted done?
My jQuery and PHP code:
<?php
chdir('../');
include("_mysql.php");
include("_settings.php");
include("_functions.php");
chdir('admin');
if (isset($_POST['rubric'])) {
if (empty($_POST['rubric']) && empty($_POST['content'])) {
echo '<div class="alert alert-error alert-box">Du måste fylla i alla fält.</div>';
}
else {
$rubric = $_POST['rubric'];
$sql = "INSERT INTO ".PREFIX."news(`date`, `poster`)
VALUES('".time()."', '".$userID."')";
mysql_query($sql);
$id = mysql_insert_id();
$sql2 = "INSERT INTO ".PREFIX."news_contents(`newsID`, `headline`, `content`)
VALUES('".$id."', '".$rubric."', '".$_POST['content']."')";
mysql_query($sql2);
echo '<div class="alert alert-box alert-success">Klart, nyheten postad.</div>';
}
}
?>
$("#form").submit(function(event) {
event.preventDefault();
var poster = $.post('addnews.php', $(this).serialize());
poster.done(function(data) {
$(".result").html(data);
});
});
Does anyone know how I can do this? Because now when I post a new the rubric and content is still there, and I dont really know how to unset the variables.
And I really still want my error, and accept message left if possible.