-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.php
72 lines (63 loc) · 1.95 KB
/
article.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
if($_COOKIE['login'] == '') {
header('Location: /reg.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<?php
$website_title = 'Добавление статьи';
require 'blocks/head.php';
?>
</head>
<body>
<?php require 'blocks/header.php'; ?>
<main class="container mt-5">
<div class="row">
<div class="col-md-8 mb-3">
<h4>Добавление статьи</h4>
<form action="" method="post">
<label for="title">Заголовок статьи</label>
<input type="text" name="title" id="title" class="form-control">
<label for="intro">Интро статьи</label>
<textarea name="intro" id="intro" class="form-control"></textarea>
<label for="text">Текст статьи</label>
<textarea name="text" id="text" class="form-control"></textarea>
<div class="alert alert-danger mt-2" id="errorBlock"></div>
<button type="button" id="article_send" class="btn btn-success mt-3">
Добавить
</button>
</form>
</div>
<?php require 'blocks/aside.php'; ?>
</div>
</main>
<?php require 'blocks/footer.php'; ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$('#article_send').click(function () {
var title = $('#title').val();
var intro = $('#intro').val();
var text = $('#text').val();
$.ajax({
url: 'ajax/add_article.php',
type: 'POST',
cache: false,
data: {'title' : title, 'intro' : intro, 'text' : text},
dataType: 'html',
success: function(data) {
if(data == 'Готово') {
$('#article_send').text('Все готово');
$('#errorBlock').hide();
} else {
$('#errorBlock').show();
$('#errorBlock').text(data);
}
}
});
});
</script>
</body>
</html>