Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Page and Site Features

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

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.

  1. There is one PHP script to be installed on the server. It is essentially an emailer, sending you the content of the submitted feedback.

  2. 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.)

  3. 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.

  1. Replace /php/ArticleFeedback.php with the correct URL to your installation of the ArticleFeedback.php PHP script.

    Remove the protocol (http:// or https://) and the domain name from the ArticleFeedback.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).

  2. 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

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC