示例#1
0
 protected function check_submission()
 {
     if (!parent::check_submission()) {
         return false;
     }
     $valid_email = is_email($_POST['email']);
     if (!$valid_email) {
         $this->errors[] = __('The email address you entered is not valid.', 'rt');
     }
     $question = get_post($_POST['question']);
     $valid_question = !empty($question);
     if (!$valid_question) {
         $this->errors[] = __('Sorry, we can\'t figure out what question you want to come back to', 'rt');
     }
     return $valid_email && $valid_question;
 }
示例#2
0
 protected function check_submission()
 {
     if (!parent::check_submission()) {
         return false;
     }
     $submission_type = $_REQUEST['submissionType'];
     // check required fields in form
     $required_fields = array('title' => 'Title', 'country' => 'Country', 'email' => 'Email', 'language' => 'Language', 'theme' => 'Theme');
     foreach ($required_fields as $key => $required_field) {
         if (empty($_REQUEST[$key])) {
             $this->errors['top_level'] = __('Some required fields were missing.', 'rt');
             $this->errors[] = "{$required_field} is required.";
         }
     }
     // check there is a media selected
     if (empty($submission_type)) {
         $this->errors['top_level'] = __('Some required fields were missing.', 'rt');
         $this->errors[] = __('You must upload at least one type of media using the 4 buttons at the top.', 'rt');
     }
     // check specific media selected was entered
     if (!in_array($submission_type, array('image', 'video', 'audio')) && !empty($submission_type) && empty($_REQUEST[$submission_type])) {
         $this->errors['top_level'] = __('Some required fields were missing.', 'rt');
         $this->errors[] = sprintf(__('You did not enter any %s.', 'rt'), $submission_type);
     }
     // check for image file
     if ($submission_type == 'image' && empty($_FILES['image']['name'])) {
         $this->errors['top_level'] = __('Some required fields were missing.', 'rt');
         $this->errors[] = __('You did not select an image.', 'rt');
     }
     // check for video file
     if ($submission_type == 'video' && empty($_FILES['video']['name'])) {
         $this->errors['top_level'] = __('Some required fields were missing.', 'rt');
         $this->errors[] = __('You did not upload a video.', 'rt');
     }
     // check for audio file
     if ($submission_type == 'audio' && empty($_FILES['audio']['name'])) {
         $this->errors['top_level'] = __('Some required fields were missing.', 'rt');
         $this->errors[] = __('You did not upload an audio file.', 'rt');
     }
     // check the correct file type was uploaded
     if (in_array($submission_type, array('audio', 'image', 'video'))) {
         if (strpos($_FILES[$submission_type]['type'], $submission_type) !== 0) {
             if ($submission_type == 'video') {
                 $file_type_error = sprintf(__('The file you chose was not a %s file. If you want to upload a different file type, please choose one of the other media buttons.', 'rt'), $submission_type);
             } else {
                 $file_type_error = sprintf(__('The file you chose was not an %s file. If you want to upload a different file type, please choose one of the other media buttons.', 'rt'), $submission_type);
             }
             if (!empty($this->errors['top_level'])) {
                 $this->errors[] = $file_type_error;
             } else {
                 $this->errors['top_level'] = $file_type_error;
             }
         }
     }
     // check the email address entered was valid
     if (!empty($_POST['email']) && !is_email($_POST['email'])) {
         $email_error = __('The email address you entered is not valid.', 'rt');
         if (!empty($this->errors['top_level'])) {
             $this->errors[] = $email_error;
         } else {
             $this->errors['top_level'] = $email_error;
         }
     }
     // check the uploaded files are ok
     foreach (array('image', 'thumbnail', 'audio', 'video') as $file) {
         if ($file == 'thumbnail' && !in_array($submission_type, array('image', 'text')) || $file != $submission_type) {
             continue;
         }
         if (!empty($_FILES[$file]['name']) && $_FILES[$file]['error'] != UPLOAD_ERR_OK) {
             if ($_FILES[$file]['error'] == UPLOAD_ERR_INI_SIZE || $_FILES[$file]['error'] == UPLOAD_ERR_FORM_SIZE) {
                 $file_error = sprintf(__('The %s you uploaded is too large. The limit is %s.', 'rt'), $file, esc_html(size_format(wp_max_upload_size())));
             } else {
                 $file_error = sprintf(__('An error occurred while saving your %s. Please try again.', 'rt'), $file);
             }
             if (!empty($this->errors['top_level'])) {
                 $this->errors[] = $file_error;
             } else {
                 $this->errors['top_level'] = $file_error;
             }
         }
     }
     if (!empty($this->errors['top_level'])) {
         return false;
     }
     return true;
 }