/** * Perform validation. * * @param array $data array of ("fieldname"=>value) of submitted data * @param array $files array of uploaded files "element_name"=>tmp_file_path * @return array of "element_name"=>"error_description" if there are errors, * or an empty array if everything is OK (true allowed for backwards compatibility too). */ public function validation($data, $files) { $errors = parent::validation($data, $files); $recipientserror = helper::validate_coupon_recipients($data['coupon_recipients']); if ($recipientserror !== true) { $errors['coupon_recipients'] = $recipientserror; } return $errors; }
/** * Perform validation. * * @param array $data array of ("fieldname"=>value) of submitted data * @param array $files array of uploaded files "element_name"=>tmp_file_path * @return array of "element_name"=>"error_description" if there are errors, * or an empty array if everything is OK (true allowed for backwards compatibility too). */ public function validation($data, $files) { // Set which fields to validate, depending on form used. if ($data['showform'] == 'csv' || $data['showform'] == 'manual') { $data2validate = array('email_body' => $data['email_body'], 'date_send_coupons' => $data['date_send_coupons']); } else { $data2validate = array('coupon_amount' => $data['coupon_amount'], 'alternative_email' => $data['alternative_email']); } $data2validate['redirect_url'] = $data['redirect_url']; $data2validate['enrolment_period'] = $data['enrolment_period']; // Validate. $errors = parent::validation($data2validate, $files); // Custom validate. if ($data['showform'] == 'amount') { // Max amount of coupons. $maxcouponsamount = get_config('block_coupon', 'max_coupons'); if ($data['coupon_amount'] > $maxcouponsamount || $data['coupon_amount'] < 1) { $errors['coupon_amount'] = get_string('error:coupon_amount_too_high', 'block_coupon', array('min' => '0', 'max' => $maxcouponsamount)); } // Alternative email required if use_alternative_email is checked. if (isset($data['use_alternative_email']) && empty($data['alternative_email'])) { $errors['alternative_email'] = get_string('error:alternative_email_required', 'block_coupon'); } } else { if ($data['showform'] == 'csv') { $csvcontent = $this->get_file_content('coupon_recipients'); if (!$csvcontent || empty($csvcontent)) { $errors['coupon_recipients'] = get_string('required'); } } else { $validationresult = helper::validate_coupon_recipients($data['coupon_recipients_manual']); if ($validationresult !== true) { $errors['coupon_recipients_manual'] = $validationresult; } } } return $errors; }