-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog_new.php
59 lines (52 loc) · 2.1 KB
/
blog_new.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
<?php
//le FORM a faire pour creer un article
//qui va le rentrer dans la DB
require_once("./php/htmlHelper.php");
require_once("./php/GeneralHelper.php");
RequireAdmin();
require_once("./php/sql.php");
$pdo = GetPDO();
GenerateHeader("homepage.jpg", "blog");
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(!empty($_POST['title']) && !empty($_POST['htmlcontent']) && !empty($_POST['descrip'])) {
$title =htmlspecialchars($_POST['title']);
$content=htmlspecialchars($_POST['htmlcontent']);
$decrip =htmlspecialchars($_POST['descrip']);
$query=$pdo->prepare('INSERT INTO blog (name , htmlcontent, description) VALUE (:title , :content, :description)');
$query->execute([
":title" =>$title,
":content" =>$content,
":description" =>$decrip,
]);
die();
}else {
die();
http_response_code(400);
header("location:/blog_new");
}
}
?>
<form class="ui form" action="/blog_new" method="post">
<input type="text" name="title" placeholder="title"><br/>
<div class="ui divider"></div>
<input id="descrip" name="descrip"onkeyup="conteur()" type="text" placeholder="description" maxlength="240">
<span id="conteur" style="position:absolute; right:0; width:20px ;height:20px; margin:20px"></span>
<div class="ui divider"></div>
<textarea id="content" name="htmlcontent" placeholder="article" columns="100" rows="20" onkeyup="updatehtml()"></textarea>
<div class="ui divider"></div>
<button style="float:right" type="submit" class="ui blue huge inverted button">publish</button>
</form>
<div id="preview"></div>
<script>
function updatehtml() {
$('#preview').html($("#content").val());
}
function conteur(){
const input = document.getElementById('descrip');
const maxlength = parseInt(input.getAttribute("maxlength"));
const conteur = document.getElementById('conteur');
const len = input.value.length;
const difference = maxlength - len;
conteur.innerHTML = difference;
};
</script>