-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
82 lines (71 loc) · 2.33 KB
/
Copy pathindex.php
File metadata and controls
82 lines (71 loc) · 2.33 KB
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
73
74
75
76
77
78
79
80
81
82
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function isValidFormId($id) {
return preg_match('/^[0-9a-zA-Z\-\_]{4,50}$/', $id) && file_exists("forms/$id") && is_dir("forms/$id");
}
if ( isset($_POST['action']) && $_POST['action'] == 'submit'
&& isset($_POST['id']) && isValidFormId($_POST['id'])
&& isset($_POST['data']) ) {
if ($_POST['id'][0] == '_') die('Error: Form inactive.');
$fid = 'forms/'.$_POST['id'];
$data = $_POST['data'];
$id = ''.date("Y-m-d_H-i-s_").rand(1,1000);
array_unshift($data, array("name" => "timestamp", "value" => $id));
$f = fopen("$fid/$id.dat.json", "w");
fwrite($f, json_encode($data));
fclose($f);
die('Form data saved.');
}
?>
<html>
<head>
<title>artform</title>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="form-builder.min.js"></script>
<script src="form-render.min.js"></script>
<script
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
</head>
<style type="text/css">
body {background: linear-gradient(to top right, #00549F, #C7DDF2);}
html,body {width:100%;}
form, #msg:not(:empty) {border-radius: 1em; padding:2em; margin:1em; background:#fff4; max-width:40rem; margin:0 auto;
}
form, form * {font-size: 1.2rem;}
</style>
<body>
<?php if(file_exists("format_header.html")) include ("format_header.html");?>
<form>
<div id="formContent"></div>
<input type="submit" />
</form>
<div id="msg"></div>
<script>
$($ => {
const id = (location.search.length > 1) ? location.search.substr(1) : null;
if (id && id.lenth > 1 && id[0] != '_') {
$.get('forms/'+id+'/form.json', function(formdata) {
$("#formContent").formRender({formData:formdata});
}, 'text').fail(function(){
$("body > form").html("<h2>There is no survey here. You are on the wrong page.</h2>");
});
$('form').on('submit', function(e) {
const data = $('form').serializeArray();
$.post('', {action: 'submit', id: id, data: data}, function(reply) {
$('body > form').remove();
$('#msg').html(reply);
});
e.preventDefault();
});
}
else{
$("body > form").html("<h2>There is no survey here. You are on the wrong page.</h2>");
}
});
</script>
</body>
</html>