diff --git a/core/includes/form.inc b/core/includes/form.inc
index 8059ea1..6b668d0 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -2017,6 +2017,22 @@ function _form_builder_handle_input_element($form_id, &$element, &$form_state) {
         drupal_array_set_nested_value($form_state['input'], $element['#parents'], NULL);
         $input_exists = TRUE;
       }
+      // Check whether the input is valid UTF-8.
+      // The variable allows sites to opt-out from the UTF-8 validation, which
+      // may be wanted when dealing with form submissions whose values originate
+      // from other sources.
+      if ($input_exists && is_string($input) && variable_get('form_validate_utf8', TRUE) && !drupal_validate_utf8($input)) {
+        // Prevent invalid UTF-8 strings from being processed by any form
+        // validation handlers.
+        $input_exists = FALSE;
+
+        // Directly throw a form validation error to prevent the form from being
+        // successfully processed with partial values.
+        $t = get_t();
+        $element_name = (!empty($element['#title']) ? $element['#title'] : $element['#parents'][0]);
+        form_error($element, $t('%name field contains illegal characters.', array('%name' => $element_name)));
+        watchdog('form', 'Invalid UTF-8 value in %name element.', array('%name' => $element_name), WATCHDOG_ERROR);
+      }
       // If we have input for the current element, assign it to the #value
       // property, optionally filtered through $value_callback.
       if ($input_exists) {
