Changeset - 79e1cca91899
[Not reviewed]
default
0 3 0
Ethan Zonca (ethanzonca) - 15 years ago 2010-11-15 19:37:47
e@ethanzonca.com
Added reCaptcha support to feedback form, fixed feedback form
3 files changed with 31 insertions and 2 deletions:
0 comments (0 inline, 0 general)
feedback-submit.php
Show inline comments
 
@@ -10,58 +10,68 @@
 
 * (at your option) any later version.
 
 *
 
 * SlatePermutate is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
  include_once 'inc/class.page.php';
 

	
 
  $feedbackpage = new page('Feedback');
 
  $subject = '[SlatePermutate] - Feedback';
 
?>
 

	
 
<h3>Thanks!</h3>
 

	
 
<?php
 
Page::session_start();
 

	
 
$ip = $_POST['ip'];
 
$httpagent = $_POST['httpagent'];
 
$fromdom = $_POST['fromdom'];
 
$nameis = $_POST['nameis'];
 
$visitormail = $_POST['visitormail'];
 
$school = $_POST['school'];
 
$school_id = isset($_SESSION['school']) ? $_SESSION['school'] : '';
 
$feedback = $_POST['feedback'];
 
$rating = $_POST['rating'];
 

	
 
$reject = FALSE;
 

	
 
if (eregi('http:', $feedback)) { 
 
  echo 'Please do not include URLs in your submission! Please click "back" and try again.';
 
  echo '<p>Please do not include URLs in your submission! Please click "back" and try again.</p>';
 
  $reject = TRUE;
 
}
 
if (empty($visitormail) || !preg_match('/^[^@]+@[^@]+\.[^@]+$/', $visitormail)) {
 
  echo '<p>Please click "back" and enter valid e-mail address.</p>';
 
  $reject = TRUE;
 
}
 
if(empty($nameis) || empty($feedback) || empty($visitormail)) {
 
  echo '<p>Please click "back" and fill in all fields.</p>';
 
  $reject = TRUE;
 
}
 

	
 
/** Try reCaptcha */
 
require_once('inc/recaptchalib.php');
 
$reCaptchaRes = recaptcha_check_answer($reCaptcha_priv, $_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
 

	
 
if(!$reCaptchaRes->is_valid) {
 
  echo '<p>Please click "back" and enter a valid reCaptcha response.</p>';
 
  $reject = TRUE;
 
}
 

	
 
if (!$reject)
 
  {
 
    $feedback = stripcslashes($feedback);
 

	
 
    $message = date('l, F j, Y, g:i a') ."
 
From: $nameis ($visitormail)
 
School: $school ($school_id)\n
 
Rating: $rating 
 
Feedback: $feedback 
 
\n
 
IP = $ip 
 
Browser = $httpagent 
 
@@ -69,14 +79,14 @@ Deployment = $fromdom
 
";
 

	
 
    $from = "From: $visitormail\r\n";
 

	
 
    /* $feedback_emails has its default set in inc/class.page.inc, can be set in config.inc */
 
    foreach($feedback_emails as $toaddr)
 
      {
 
	mail($toaddr, $subject, $message, $from);
 
      }
 

	
 
    echo '<p>Thanks for helping make SlatePermutate better. Your feedback is greatly appreciated.</pi>';
 
    echo '<p>We will attempt to respond via email if your feedback lends itself to a response.</p>';
 

	
 
  }
 
    $feedbackpage->foot();
feedback.php
Show inline comments
 
@@ -10,40 +10,47 @@
 
 * (at your option) any later version.
 
 *
 
 * SlatePermutate is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
  include_once 'inc/class.page.php'; 
 

	
 
  $feedbackpage = new page('Feedback');
 
  $ipi = $_SERVER['REMOTE_ADDR'];
 
  $fromdom = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
  $httpagenti = $_SERVER['HTTP_USER_AGENT'];
 
?>
 

	
 
<form action="feedback-submit.php" method="post">
 
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
 
<input type="hidden" name="fromdom" value="<?php echo $fromdom ?>" />
 
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
 

	
 
<h2>Feedback Form</h2>
 
<label for="nameis">Name: </label><input type="text" name="nameis" size="20" /><br />
 
<label for="visitormail">Email:&nbsp; </label><input type="text" name="visitormail" size="20" /> <span class="graytext">(if you want us to get back to you)</span><br />
 
<label for="school">School: </label><input type="text" name="school" size="20" /> <span class="graytext">(if relevant to your feedback)</span><br />
 

	
 
<br/> Overall Rating:<br/> <input checked="checked" name="rating" type="radio" value="Good" />Good <input name="rating" type="radio" value="Buggy" />Buggy  <input name="rating" type="radio" value="Needs more features" />Needs more features <input name="rating" type="radio" value="Don't know" />Don't Know
 

	
 
<br /><br />
 
<h3>General Comments</h3>
 
<p>
 
<textarea name="feedback" rows="6" cols="40"></textarea>
 
</p>
 

	
 
<?php
 
  require_once('inc/recaptchalib.php');
 
  echo recaptcha_get_html($reCaptcha_pub); 
 
?>
 

	
 
<input class="gray" type="submit" value="Submit Feedback" />
 
</form>
 

	
 
<?php
 
$feedbackpage->foot();
inc/config.inc.example
Show inline comments
 
@@ -48,12 +48,24 @@
 
/* $ga_trackers = array(); */
 
/* $ga_trackers = array('UA-XXXXXXXX-X'); */
 

	
 
/**
 
 * \brief
 
 *   List of email addresses to send feedback form submissions to.
 
 *
 
 * Set this to a PHP array of email addresses to which feedback
 
 * submissions should be mailed.
 
 */ 
 
/* $feedback_emails = array('ethanzonca@gmail.com, ngelderloos7@gmail.com, ohnobinki@ohnopublishing.net'); */
 
/* $feedback_emails = array('user@example.org'); */
 

	
 
/**
 
 * \brief
 
 *   Keys to use with reCaptcha for feedback form submissions
 
 *
 
 * Set to your public and private keys obtained from https://www.google.com/recaptcha/
 
 * Be sure to keep your private key secret.
 
 */
 
/* $reCaptcha_priv = ''; */
 
/* $reCaptcha_pub = ''; */ 
 

	
 

	
0 comments (0 inline, 0 general)