I found a need for a limited-time feedback form, given that some converted entries on a project had been checked, but ones after X date were done as part of the massive sweep (and were more likely to have errors). Sometimes readers will help out, and let you know what you’ve screwed up, or at least, it makes some folks feel good to find mistakes.
First I set up a temporary db table for the feedback, which captures all the information from a multiple-choice form that basically lists the most common/likely errors I’d been seeing post-conversion: things like dropped or incorrect categories, missing title, missing excerpt, screwy formatting on the post body.
CREATE TABLE `wp_errorform` ( `id` bigint(20) NOT NULL auto_increment, `postid` bigint(20) NOT NULL, `userip` varchar(14) NOT NULL, `cat1` int(1) default NULL, `cat2` int(1) default NULL, `cat3` int(1) default NULL, `cat4` int(1) default NULL, `cat5` int(1) default NULL, `cat6` int(1) default NULL, `title` int(1) default NULL, `hdr` int(1) default NULL, `ent` int(1) default NULL, `ext` int(1) default NULL, PRIMARY KEY (`id`) ) AUTO_INCREMENT=4 ;
For the form itself, I created an include file, inc_issues.php. Basically it’s an all-in-one, without a separate proc page, just because I was being lazy. (That’s the same reason you see a db conn as well as WP globals, because I’ve gotten into the strange habit of adding using the formal db conn with only randomly using the WP functions, when it occurs to me.)
if($_POST['report'] == 'Z') {
$user_ip = $_POST['user_ip'];
$postid = $_POST['post_id'];
$cat1 = $_POST['cat1'];
$cat2 = $_POST['cat2'];
$cat3 = $_POST['cat3'];
$cat4 = $_POST['cat4'];
$cat5 = $_POST['cat5'];
$cat6 = $_POST['cat6'];
$title = $_POST['title'];
$exc = $_POST['ext'];
$hdr = $_POST['hdr'];
$ent = $_POST['ent'];
$con = mysql_connect("db-host","db-name","db-pw");
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db("db-name", $con);
global $wpdb;
$sql = ("INSERT INTO `wp_erform` (`postid` , `userip` , `cat1` , `cat2` , `cat3` , `cat4` , `cat5` , `cat6` , `title` , `hdr` , `ent` , `ext` )
VALUES ('$postid', '$user_ip','$cat1', '$cat2', '$cat3', '$cat4', '$cat5', '$cat6', '$title', '$hdr', '$ent', '$ext' )");
$result = mysql_query($sql) or die(mysql_error());
$result;
// replace form with thank-you image when done
$banner = "thank-you.jpg";
} ?>
<a href="javascript:animatedcollapse.toggle('critsiscrits')"><center><img src="/images/<?php echo $banner; ?>" alt="You're invited to tell us what's broken on this page."></center></a>
<div id="critsiscrits" style="display:none">
<form action="archives/<?php the_ID(); ?>" method="post">
<input type="hidden" name="report" value="Z">
<input type="hidden" name="postid" value="<?php the_ID(); ?>">
<p><!-- note about the form & request for help goes here --></p><p><hr class="dash">
</p><p>
<b>Categories</b> -- click the ones you think better apply. (Current are pre-selected.)</p><p>
<input type="checkbox" value="1" <?php if (in_category('3')) echo 'checked'; ?> name="cat1">
<input type="checkbox" value="1" <?php if (in_category('4')) echo 'checked'; ?> name="cat2">
<input type="checkbox" value="1" <?php if (in_category('5')) echo 'checked'; ?> name="cat3">
<input type="checkbox" value="1" <?php if (in_category('6')) echo 'checked'; ?> name="cat4">
<input type="checkbox" value="1" <?php if (in_category('7')) echo 'checked'; ?> name="cat5">
<input type="checkbox" value="1" <?php if (in_category('17')) echo 'checked'; ?> name="cat6">
<hr class="dash"><p>
<table width=100%><tr><td width=25%>title <br>
<select name="title"><option value=""> </option>
<option value="1"> title cuts off </option>
<option value="2"> wrong title </option>
<option value="3"> fix spelling/capitals </select>
</td><td width=25%>excerpt <br>
<select name="ext"><option value=""> </option>
<option value="1"> excerpt cuts off </option>
<option value="2"> not from story </option>
<option value="3"> fix spelling/capitals </select>
</td><td width=25%>post body<br>
<select name="ent"><option value=""> </option>
<option value="1"> no content for post </option>
<option value="2"> fix paragraph breaks </option>
<option value="3"> mis-formatted </select>
</td><td width=25%>headers in post<br>
<select name="hdr"><option value=""> </option>
<option value="1"> headers not formatted</option>
<option value="2"> headers should be regular text</option>
<option value="3"> headers mis-formatted </select>
</td></tr></table>
<!-- ...and so on, for the form. -->
<hr class="dash"><center>
<input type="hidden" name="user_ip" value="<?php echo get_the_ip(); ?>">
<input type="hidden" name="post_id" value="<?php echo the_ID(); ?>">
<input name="submit" type="image" src="images/btn_report.jpg" alt="report" value="report" />
<a href="<?php the_permalink();?>"><img src="images/btn_cancel.jpg"></a>
</center></form>
I added a user-ip catcher to the functions.php file, which is a really simple thing for something that sounds so complex:
/*----------------------------------------------
GET USER IP ADDRESS
----------------------------------------------*/
function get_the_ip() {
if (empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip_address = $_SERVER["REMOTE_ADDR"];
} else {
$ip_address = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
At the end of the content section on single.php, I added a bit of code to check the date and add the feedback form only if the post were added after X date.
<?php
global $post;
$this_date = the_date('Y-m-d', '', '', FALSE);
//echo $this_date;
$this = strtotime($this_date);
$start = "2009-06-15";
$that = strtotime($start);
if ($this > $that) {
$user_ip = get_the_ip();
$fedbacked = $wpdb->get_results("SELECT `id` FROM izumi_erform WHERE `postid`='$post->ID' AND `userip`='$user_ip'");
$done = count($fedbacked);
if (($done =="") || ($done > 1)) {
$banner = "images/please.jpg";
echo '<div class="grid_12 tobo">';
include (TEMPLATEPATH . '/inc_issues.php');
echo '</div>';
}
}
?>
And the last step was to add it so it’d show up on the dashboard, where any admin/editors could see it and know to fix the post.
/*----------------------------------------------
DASHBOARD WIDGET
----------------------------------------------*/
function erf_dashboard_widget_func() {
global $wpdb;
$reports = $wpdb->get_results("SELECT * FROM wp_errorform ORDER BY postid ASC");
foreach ($reports as $report) {
$idx = $report->id;
$postid = $report->postid;
echo '<p>'.$idx.'. <b>'.$postid .': <a href="'. get_permalink($postid) .'" target="new">'.get_the_title($postid).'</a></b> => ';
// show categories selected (uses colored images as visual reminders, but text+font-color would use the same pattern)
if ($report->cat1 =="1") { $cat1="3g3"; } else { $cat1="3g1"; }
if ($report->cat2 =="1") { $cat2="4p3"; } else { $cat2="4p1"; }
if ($report->cat3 =="1") { $cat3="5o3"; } else { $cat3="5o1"; }
if ($report->cat4 =="1") { $cat4="6b3"; } else { $cat4="6b1"; }
if ($report->cat5 =="1") { $cat5="7r3"; } else { $cat5="7r1"; }
if (in_category(3, $postid)) { $cat1="3g2"; }
if (in_category(4, $postid)) { $cat2="4p2"; }
if (in_category(5, $postid)) { $cat3="5o2"; }
if (in_category(6, $postid)) { $cat4="6b2"; }
if (in_category(7, $postid)) { $cat5="7r2"; }
echo ' <img src="images/dash/'.$cat1.'.jpg"> ';
echo ' <img src="images/dash/'.$cat2.'.jpg"> ';
echo ' <img src="images/dash/'.$cat3.'.jpg"> ';
echo ' <img src="images/dash/'.$cat4.'.jpg"> ';
echo ' <img src="images/dash/'.$cat5.'.jpg"> ';
// links to delete proc-page I never actually bothered to make
echo ' <a href="report-proc.php&idx='.$idx.'">[del]</a> ';
echo $report->userip;
echo '</b><blockquote>';
// text details
if ($report->title==1) {echo '- title cuts off -';}
elseif ($report->title==2) {echo '- wrong title -';}
elseif ($report->title==3) {echo '- fix spelling/capitals -';}
if ($report->exc==1) {echo '- excerpt cuts off -';}
elseif ($report->exc==2) {echo '- not from story -';}
elseif ($report->exc==3) {echo '- fix spelling/capitals -';}
if ($report->ent==1) {echo '- text is missing -';}
elseif ($report->ent==2) {echo '- fix paragraph breaks -';}
elseif ($report->ent==3) {echo '- entire story is bold/italic -';}
if ($report->hdr==1) {echo '- headers not formatted -';}
elseif ($report->hdr==2) {echo '- headers should be regular text -';}
elseif ($report->hdr==3) {echo '- headers mis-formatted -';}
echo '</blockquote><hr></p>';
}
}
function add_erf_dashboard_widget() {
wp_add_dashboard_widget('erf_dashboard_widget', 'Reported Errors List', 'erf_dashboard_widget_func');
}
// Hoook into the 'wp_dashboard_setup' action to register functions
add_action('wp_dashboard_setup', 'add_erf_dashboard_widget' );
Note: not all of the field names and form names match, because the actual form had like sixteen things (mostly related to specifics for the site that would make any example top-heavy), so if you want to use this as example, you will need to mess with it a little to fit it to what you want. But the basic function worked nicely, and since I’ve been in the db tables so much while working with the conversion process, I got into the habit of deleting manually as I needed to. A delete proc-page wouldn’t be that hard, but I was just being lazy.
One other note: the feedback form would hide until clicked, and for that I used a javascript animated collapse I found on DHTML scripts, I think it was. Pretty nifty, and relatively compact for what it does.