Feedback Within Articles
So, what would people say if they were able to send you feedback from within the article they are reading?
Now, you can know.
Some readers will participate. Some will not. When they do, the feedback can be invaluable for either revising the article or to keep in mind when writing future articles.
Implement this Article Feedback system and let your site visitors tell you what they are thinking at the time they are thinking it.
Intermittently within the article (usually immediately following a question or idea) readers are asked for their reactions.
No personally identifying information is collected, unless voluntarily provided in the text box. This feedback system asks for thoughts and reactions, not identities.
When feedback is provided, it is emailed to you. The web page URL and the person's IP address are included.
How Article Feedback Works
There are three parts that interact together.
-
There is one PHP script to be installed on the server. It is essentially an emailer, sending you the content of the submitted feedback.
-
Each page that has at least one Article Feedback form has certain Ajax JavaScript in its source code. (Because PHP is used to create some of the Ajax code, it cannot be pulled in from an external file. It must be published in the source code of the web page containing one or more Article Feedback forms.)
-
Web pages may have as many Article Feedback forms as is suitable for your article.
When an Article Feedback form is used, the feedback is sent to the Ajax JavaScript on that page. The Ajax JavaScript sends it to the PHP script. And the PHP script sends you the email.
Ajax is used so the web page does not reload when the feedback is submitted.
Implementing Article Feedback
There are three parts to the implementation of Article Feedback.
Step 1
The first step is to install the PHP script on your server. Here is the source code. Notes follow.
<?php /* Article Feedback Version 1.0 May 25, 2020 Will Bontrager Software LLC https://www.willmaster.com/ */ /*************************************/ /* Customizations */ // The email address for sending article feedback. $EmailAddress = "will@example.com"; // The subject line for the email. $EmailSubject = "Article Feedback Message Enclosed"; /* End of customization */ /*************************************/ $PostData = array(); foreach( $_POST as $k => $v ) { $PostData[] = "$k:\n\t$v"; } mail($EmailAddress,$EmailSubject,implode("\n\n",$PostData),"From: $EmailAddress"); exit; ?>
Notes —
The only customization for the PHP script is the email address to send the feedback to and the subject line for the email. Both of those are colored blue in the above source code.
Name the PHP script ArticleFeedback.php
or other *.php
file name that you prefer. Upload the script to your domain's server and make a note of its URL.
Step 2
Next, get the Ajax JavaScript ready for web pages that will solicit article feedback.
The Ajax JavaScript assumes the web page is a PHP page. It uses PHP to determine the user's IP address.
Here is the source code. Notes follow.
<script type="text/javascript"> function ArticleFeedback(id) { var url = "/php/ArticleFeedback.php"; var confirmation = "Your feedback has been sent."; var fieldid = document.getElementById(id); if( fieldid.value == confirmation ) { return; } var http = new XMLHttpRequest(); if( ! http ) { return; } var params = new Array(); params.push( "this_page_URL=" + encodeURIComponent(document.URL) ); params.push( encodeURIComponent(id) + "=" + encodeURIComponent(fieldid.value) ); params.push( "submitter_IP=" + encodeURIComponent("<?php echo($_SERVER['REMOTE_ADDR']) ?>") ); http.onreadystatechange = function() {} http.open("POST",url,true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.send(params.join("&")); fieldid.value = confirmation; } </script>
Notes —
There are two places to customize.
-
Replace
/php/ArticleFeedback.php
with the correct URL to your installation of theArticleFeedback.php
PHP script.Remove the protocol (
http://
orhttps://
) and the domain name from theArticleFeedback.php
script's URL. It will ensure the same URL and domain that is used for accessing the web page is also used with Ajax (an Ajax requirement). -
Replace
Your feedback has been sent.
with whatever message you want to show within the text box after the person submits their feedback.
Keep a copy of the Ajax JavaScript. You'll insert a copy into the source code of each page where the Article Feedback form is published.
Step 3
Create the feedback form or forms for the article.
Here is the template for the form. Notes follow.
<textarea id="id-for-this-particular-form" style="width:100%; height:4em;" placeholder="Will this be useful for you?"></textarea> <input type="button" style="width:100%" onclick="ArticleFeedback('id-for-this-particular-form')" value="Send Feedback">
Notes —
The code creates a textarea box to type in the feedback and a button to send the feedback.
Optionally, the placeholder for the textarea box, the text for the button, and the style for both of them may be changed as appropriate for your installation.
But what must be conformed is the two instances of id-for-this-particular-form
— one in the textarea field and one in the button field.
Both instances of id-for-this-particular-form
must be identical. And, if you have more than feedback form on a page, each feedback form/button set needs their own id that is different than the other feedback form/button sets.
If you have two article feedback forms, for example, the first form's two instances might be feedback-in-middle-of-article
and the second feedback form's two instances might be feedback-at-end-of-article
.
Put as many article feedback forms within your article as you wish. Only one copy of the Ajax JavaScript needs to be on the page for however many article feedback forms you utilize.
Conclusion
The article feedback system can help you understand how your audience perceives your content, which is a key to writing content the audience can easily understand.
Because the feedback is anonymous, it encourages honest response.
(This article first appeared with an issue of the Possibilities newsletter.)
Will Bontrager