# HG changeset patch # User Nathan Phillip Brink # Date 2013-04-05 00:49:03 # Node ID 1c451d4983166e368fc087955ddc70edcfc298cf # Parent 84dacca3fe100be1a5dd90e3780ae68d001c4a38 Enable users who fail to meet all the feedback requirements tested in feedback-submit.php to return to feedback.php without losing their comments (when using the “Try again” button). diff --git a/feedback-submit.php b/feedback-submit.php --- a/feedback-submit.php +++ b/feedback-submit.php @@ -31,23 +31,30 @@ if ($use_captcha) $feedbackpage = page::page_create('Feedback'); $feedbackpage->head(); -$subject = '[SlatePermutate] - Feedback'; -?> -

Thanks!

+if (isset($_GET['success'])) + { + echo '

Thanks

' . PHP_EOL + . '

Thanks for helping make SlatePermutate better. Your feedback is greatly appreciated.

' . PHP_EOL + . '

We will attempt to respond via email if your feedback lends itself to a response.

' . PHP_EOL; + $feedbackpage->foot(); + exit(); + } -Please do not include URLs in your submission! Please click "back" and try again.

'; + $messages .= '

Please do not include URLs in your submission!

' . PHP_EOL; $reject = TRUE; } -if (empty($visitormail) || !preg_match('/^[^@]+@[^@]+\.[^@]+$/', $visitormail)) { - echo '

Please click "back" and enter valid e-mail address.

'; +if (empty($visitormail) || !preg_match('/^[^@]+@[^@]+\.[^@]+$/', $visitormail) + || !($visitormail = filter_var($visitormail, FILTER_VALIDATE_EMAIL))) + { + $messages .= '

Please enter a valid e-mail address.

' . PHP_EOL; $reject = TRUE; } if(empty($nameis) || empty($feedback) || empty($visitormail)) { - echo '

Please click "back" and fill in all fields.

'; + $messages .= '

You must fill in in all of the fields.

' . PHP_EOL; $reject = TRUE; } /** Check the captcha */ if ($use_captcha) { - if (!$securimage->check($_REQUEST['captcha_code'])) + if (empty($_REQUEST['captcha_code']) + || !$securimage->check($_REQUEST['captcha_code'])) { - echo '

Your captcha response was incorrect or expired. Please try again.

'; + $messages .= '

Your captcha response was incorrect or expired.

'; $reject = TRUE; } } +$success = FALSE; if (!$reject) { $feedback = stripcslashes($feedback); $message = gmdate('l, F j, Y, g:i a') ." -From: $nameis ($visitormail) +From: $nameis <$visitormai> School: $school ($school_id)\n Rating: $rating Feedback: $feedback @@ -102,7 +114,11 @@ saved_schedules = $saved_schedules /* $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); + $success = mail($toaddr, $subject, $message, $from); + if (!$success) + { + $messages .= '

This Slate Permutate installation is misconfigured and unable to send email. Please contact the administrator of this website using a more direct means if possible.

' . PHP_EOL; + } } if($feedback_disk_log) { @@ -110,7 +126,16 @@ saved_schedules = $saved_schedules fwrite($file, $message . "----------------------------------------\n"); fclose($file); } - echo '

Thanks for helping make SlatePermutate better. Your feedback is greatly appreciated.

'; - echo '

We will attempt to respond via email if your feedback lends itself to a response.

'; } - $feedbackpage->foot(); +if ($success) + page::redirect('feedback-submit.php?success'); +else + echo '

Error

' . PHP_EOL + . $messages; + +$repost = array(); +foreach ($user_supplied_params as $user_supplied_param) + $repost[$user_supplied_param] = $_POST[$user_supplied_param]; +echo $feedbackpage->query_formbutton('feedback.php', $repost, $feedbackpage->entities('try again'), '

Consider the error messages, then ', '.

'); + +$feedbackpage->foot(); diff --git a/feedback.php b/feedback.php --- a/feedback.php +++ b/feedback.php @@ -23,9 +23,8 @@ require_once 'inc/class.schedule.php'; $feedbackpage = page::page_create('Feedback'); $feedbackpage->head(); -$ipi = $_SERVER['REMOTE_ADDR']; + $fromdom = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; -$httpagenti = $_SERVER['HTTP_USER_AGENT']; $referrer = ''; if (!empty($_SERVER['HTTP_REFERER'])) @@ -51,13 +50,11 @@ if (isset($_GET['feedback']))
- - - + - - + +
(if relevant to your feedback)
(if relevant to your feedback)
diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -823,6 +823,25 @@ class page /** * \brief + * Return an array of name=value pairs that are urlencoded. + * + * Supports query_string() and query_formbutton(). + */ + private static function _uriencode_query_array(array $query) + { + $query_string_parts = array(); + foreach ($query as $param => $values) + { + if (!is_array($values)) + $values = array($values); + foreach ($values as $value) + $query_string_parts[] = rawurlencode($param) . '=' . rawurlencode($value); + } + return $query_string_parts; + } + + /** + * \brief * Form a query string from a map. * * \param $query @@ -836,17 +855,136 @@ class page */ public static function query_string(array $query, $question = TRUE) { - $query_string_parts = array(); - foreach ($query as $param => $values) + $query_string_parts = self::_uriencode_query_array($query); + if (count($query_string_parts)) + return ($question ? '?' : '') . implode('&', $query_string_parts); + return ''; + } + + /** + * \brief + * Return an HTML form button which submits all keys, as many of + * them with GET as possible. + * + * Allows one to automatically delegate fatter values to be POSTed + * to prevent the querystring from getting too long and making the + * URI itself become too long. Always returns a with a + * ' . $button_post_html . PHP_EOL + . ''; } /** @@ -958,4 +1096,16 @@ class page return ' /'; return ''; } + + /** + * \brief + * Encode things using htmlentities() with proper precautions. + */ + public static function entities($text) + { + $opts = ENT_QUOTES; + if (defined('ENT_XML1')) + $opts |= ENT_XML1; + return htmlentities($text, $opts, 'utf-8'); + } }