implemented "success messages" for submitted forms (?msg=...)

pull/2/head
Ondřej Hruška 7 years ago
parent d831d47f53
commit 64c1ebbf8f
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 19
      compile_html.php
  2. 24
      js/appcommon.js
  3. 2
      pages/_head.php
  4. 5
      sass/form/_form_layout.scss

@ -22,9 +22,22 @@ ob_start();
foreach($_pages as $_k => $p) {
if ($p->bodyclass == 'api') {
if (ESP_DEMO) {
$target = 'term.html';
echo "Generating: ~$_k.html -> $target\n";
$s = "<!DOCTYPE HTML><meta http-equiv=\"refresh\" content=\"0;url=$target\">";
echo "Generating: ~$_k.html (bounce)\n";
if ($_k=='index') {
$s = "<!DOCTYPE HTML><meta http-equiv=\"refresh\" content=\"0;url=term.html\">";
}
else {
$s = "<!DOCTYPE HTML>
<script>
var ref = document.referrer;
var qat = document.referrer.indexOf('?');
if (qat !== -1) ref = ref.substring(0, qat)
location.href=ref+'?msg=Request ignored, this is a demo.';
</script>";
}
} else {
continue;
}

@ -90,24 +90,32 @@ $.ready(function () {
// (a way to pass errors back from server via redirect)
let errAt = window.location.search.indexOf('err=')
if (errAt !== -1 && qs('.Box.errors')) {
let errs = window.location.search.substr(errAt + 4).split(',')
let errs = decodeURIComponent(window.location.search.substr(errAt + 4)).split(',')
let humanReadableErrors = []
errs.forEach(function (er) {
let lbls = qsa('label[for="' + er + '"]')
for (let i = 0; i < lbls.length; i++) {
let lbl = lbls[i]
lbl.classList.add('error')
if (i === 0) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, ''))
if (lbls) {
for (let i = 0; i < lbls.length; i++) {
let lbl = lbls[i]
lbl.classList.add('error')
if (i === 0) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, ''))
}
} else {
humanReadableErrors.push(er)
}
// else {
// hres.push(er)
// }
})
qs('.Box.errors .list').innerHTML = humanReadableErrors.join(', ')
qs('.Box.errors').classList.remove('hidden')
}
let msgAt = window.location.search.indexOf('msg=')
if (msgAt !== -1 && qs('.Box.message')) {
let msg = decodeURIComponent(window.location.search.substr(msgAt + 4))
qs('.Box.message').innerHTML = msg
qs('.Box.message').classList.remove('hidden')
}
modal.init()
notify.init()

@ -32,4 +32,6 @@ if (strpos($_GET['BODYCLASS'], 'cfg') !== false) {
<span class="lead"><?= tr('form_errors') ?></span>&nbsp;<span class="list"></span>
</div>
<div class="Box message hidden"></div>
<?php endif; ?>

@ -12,6 +12,11 @@ form { @include naked(); }
}
}
.Box.message {
font-weight: bold;
color: #0fca50;
}
.Row {
vertical-align: middle;
margin: 12px auto;

Loading…
Cancel
Save