Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISS-04 - Submit from the html to the processor and return results. #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
25 changes: 25 additions & 0 deletions comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<head>
<title>Cool App - Comments</title>
</head>
<body>
<h2>Comments Area!</h2>

<p>
<p>Enter Comments:</p>
<br />

<p>
<form action=POST method='commentsProcessor.php'>
<textarea name="comment"></textarea>
<input type='submit' name='submit' value='Submit Comment'>
</form>
</p>
<br />

<p>
<strong>&nbsp;link to <a href="/">HOME</a>&nbsp;</strong>
</p>
</p>
</body>
</html>
Empty file added comments/.gitkeep
Empty file.
30 changes: 30 additions & 0 deletions commentsProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$comment = $_REQUEST['comment'];

$filepath = __DIR__ . '/comments/';

try {
if (!file_exists($filepath)) {
$mkdirResult = mkdir($filepath);
if (!$mkdirResult) {
throw new Exception('Failed to create comments directory.', 10001);
}
}
$filename = time() . getmypid();
$wroteCount = file_put_contents($filepath.$filename, $comment);
$response = json_encode([
'success' => true,
'wroteCount' => $wroteCount
]);
} catch (Exception $exception) {
$response = json_encode([
'success' => false,
'errorMessage' => $exception->getMessage(),
'errorCode' => $exception->getCode()
]);
}

header('Location: /index.php?response='. $response);

exit();
29 changes: 0 additions & 29 deletions index.html

This file was deleted.

1 change: 1 addition & 0 deletions index.html
46 changes: 46 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<html>
<head>
<title>Cool App</title>
</head>
<body>
<?php
if (array_key_exists('response', $_REQUEST)) {
$response = $_REQUEST['response'];
$array = json_decode($response);
if (!$array) {
print "<h2>The results were: </h2><p>";
if ($array['success']) {
print $array['wroteCount'] . " bytes were stored.";
} else {
print "There was an error: <br />"
. "errorMessage => " . $array['errorMessage'] . "<br />"
. "errorCode => " . $array['errorCode'] . "<br />";
}
print "<br /></p>";
}
}
?>
<h2>This App is Good.</h2>

<p>
<br />

<h1>You can edit this demo text!</h1>
<br />

<h2>How to use the editor:</h2>
<br />

<p>
Paste your documents in the visual editor on the left or your HTML code in the source editor in the right. <br />
Edit any of the two areas and see the other changing in real time.&nbsp;
</p>
<br />

<p>Click the Clean button to clean your source code.</p>
<br />

<p><strong>&nbsp;link this to like the&nbsp;<a href="#comments" target="_blank" rel="noopener">comments</a></strong></p>
</p>
</body>
</html>