Documenation:
https://centerkey.com/php
Last active
June 18, 2024 09:09
-
-
Save dpilafian/e7809ad40089fad164609c54a4b7d1a4 to your computer and use it in GitHub Desktop.
Feedback form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* PERFECT PHP - centerkey.com/php - MIT or WTFPL (your choice) */ | |
/* PERFECT style */ | |
form.perfect { display: flex; flex-direction: column; max-width: 25em; background-color: whitesmoke; color: dimgray; border: 1px solid; border-radius: 2px; padding: 0px; margin: 0px auto 20px auto; } | |
form.perfect >* { margin: 0px 20px 20px 20px } | |
form.perfect h2 { font-size: 1.2rem; text-align: center; color: white; padding: 0.3em; margin: 0px 0px 20px 0px; } | |
form.perfect label { display: block; font-size: 1.0rem; text-align: left; margin-bottom: 20px; } | |
form.perfect input, form.perfect select, form.perfect textarea { width: 100%; max-width: 100%; font-size: 1.2rem; margin: 0px; } | |
form.perfect textarea { height: 4.1em; } | |
form.perfect input, form.perfect textarea { box-sizing: border-box; border: 1px solid silver; border-radius: 5px; padding: 0.3em; } | |
form.perfect fieldset { border: none; padding: 0px; } | |
form.perfect fieldset legend { font-size: 1.0em; } | |
form.perfect fieldset label { display: flex; align-items: center; padding-left: 1.2em; margin-bottom: 0.1em; } | |
form.perfect fieldset label input { width: auto; margin-right: 0.3em; } | |
form.perfect nav { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; } | |
form.perfect nav button { font-size: 1.1rem; font-weight: bold; color: white; background-color: dimgray; border: none; border-radius: 0.4em; padding: 0.6em 1.2em; cursor: pointer; transition: all 500ms; } | |
form.perfect nav button:hover:not(:disabled), form.perfect nav button:focus { background-color: black; } | |
form.perfect nav small { font-size: 0.6rem; color: gray; } | |
form.perfect nav small a { color: gray; background-color: transparent; text-decoration: none; border: none; outline: none; } | |
/* PERFECT colors */ | |
form.perfect { border-color: seagreen; } /* outer color */ | |
form.perfect h2 { background-color: seagreen; } /* outer color */ | |
form.perfect input, form.perfect textarea { background-color: mintcream; } /* input fields */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form class=perfect> | |
<h2>Send us a message</h2> | |
<label> | |
<span>Message:</span> | |
<textarea name=message placeholder="Enter your message"></textarea> | |
</label> | |
<label> | |
<span>Name:</span> | |
<input name=name placeholder="Enter your name"> | |
</label> | |
<label> | |
<span>Email:</span> | |
<input name=email type=email placeholder="Enter your email"> | |
</label> | |
<nav> | |
<small>Powered by <a href=https://centerkey.com/php>PERFECT</a></small> | |
<button type=submit>Send</button> | |
</nav> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const form = globalThis.document.querySelector('form.perfect'); | |
form.method = 'post'; | |
form.action = 'perfect.php'; | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/////////////////////////////////////////////////////// | |
// PERFECT PHP v2.3.1 (June 18, 2024) // | |
// Process a web form to extract the user input and // | |
// then email the data to a predefined recipient. // | |
// MIT License or WTFPL (your choice) // | |
// https://centerkey.com/php // | |
/////////////////////////////////////////////////////// | |
// Configuration settings | |
$sendFrom = "Feedback Message <message@yourdomain.com>"; | |
$sendTo = "username@yourdomain.com"; | |
$subjectLine = "Feedback Submission"; | |
$thanksUrl = "thanks.html"; //confirmation page | |
// Build message body from web form input | |
$lines = array($_SERVER["SERVER_NAME"], ''); | |
foreach ($_POST as $field=>$value) | |
array_push($lines, "$field: $value"); | |
array_push($lines, '', @gethostbyaddr($_SERVER["REMOTE_ADDR"]), ''); | |
$body = htmlspecialchars(implode(PHP_EOL, $lines), ENT_NOQUOTES); | |
// Send email and direct browser to confirmation page | |
$valid = str_word_count(reset($_POST)) > 2; //words in first field | |
if ($valid) //simplistic check to reduce spam | |
mail($sendTo, $subjectLine, $body, "From: $sendFrom"); | |
header("Location: $thanksUrl"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###################################### | |
# PERFECT PHP # | |
# Gist developer's script # | |
# MIT License or WTFPL (your choice) # | |
###################################### | |
# To make this file runnable: | |
# $ chmod +x *.sh.command | |
banner="Publish PERFECT PHP" | |
projectHome=$(cd $(dirname $0); pwd) | |
pkgInstallHome=$(dirname $(dirname $(which httpd))) | |
apacheCfg=$pkgInstallHome/etc/httpd | |
apacheLog=$pkgInstallHome/var/log/httpd/error_log | |
webDocRoot=$(grep ^DocumentRoot $apacheCfg/httpd.conf | awk -F'"' '{ print $2 }') | |
displayIntro() { | |
cd $projectHome | |
echo | |
echo $banner | |
echo $(echo $banner | sed s/./=/g) | |
pwd | |
version=$(grep "// PERFECT PHP v" perfect.php | awk '{ print $4 }') | |
echo $version | |
echo | |
} | |
lintPhp() { | |
cd $projectHome | |
echo "Linting:" | |
php --syntax-check *.php | |
echo | |
} | |
publishWebFiles() { | |
# For debugging: | |
# echo '<pre>', var_dump($valid, $sendTo, $subjectLine, $body, "From: $sendFrom"), '</pre>'; | |
cd $projectHome | |
publishSite=$webDocRoot/centerkey.com | |
publishFolder=$publishSite/php | |
publish() { | |
echo "Publishing:" | |
mkdir -p $publishFolder | |
cp -v *.css *.php $publishFolder | |
cp -v perfect.php $publishFolder/archive/perfect-$version.php.txt | |
cp -v perfect.html $publishFolder/perfect.html.txt | |
cp -v perfect.js $publishFolder/perfect.js.txt | |
sed -e "s/Feedback Message/PERFECT Feedback/" -e "s/yourdomain/centerkey/" \ | |
-e "s/username/feedback/" perfect.php > $publishFolder/perfect-real.php | |
echo | |
} | |
test -w $publishSite && publish | |
} | |
launchBrowser() { | |
cd $projectHome | |
url=https://centerkey.com/php | |
test -w $publishSite && url=http://localhost/centerkey.com/php | |
echo "Opening:" | |
echo $url | |
sleep 2 | |
open $url | |
echo | |
} | |
displayIntro | |
lintPhp | |
publishWebFiles | |
launchBrowser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment