post_id = $post_id; $this->cform_code = get_post_meta($post_id, '_alchemyst_forms_contact-form-code', true); $dom = new Dom; $this->dom = $dom->load($this->cform_code); $this->notifications = Alchemyst_Forms_Notifications::get_notifications($post_id); } /** * Validate with all methods in the $validator_methods_class * This class can be extended and applied back with a filter to provide additional (or overwrite) field validation */ function validate() { $validator_methods_class = apply_filters('alchemyst-forms:validator-class', 'Alchemyst_Forms_Validator_Methods'); $responses = array(); foreach (get_class_methods($validator_methods_class) as $method) { $responses[] = call_user_func(array($validator_methods_class, $method), $this->post_id, $this->cform_code, $this->dom); } // Notification validators are able to be implemented purely through filters and actions. This validator framework // Allows for that to hapen. $notification_validators = array( 'email' => 'Alchemst_Forms_Notification_Validator_Methods', ); $notification_validators = apply_filters('alchemyst_forms:form-notification-validator-classes', $notification_validators); foreach ($this->notifications as $notification) { if (!isset($notification_validators[$notification->type])) continue; foreach (get_class_methods($notification_validators[$notification->type]) as $method) { $responses[] = call_user_func(array($notification_validators[$notification->type], $method), $this->post_id, $notification); } } if (empty($this->notifications)) { $show_no_notification_warning = apply_filters('alchemyst_forms:show-no-notification-warning', true); if ($show_no_notification_warning) { $responses[] = Alchemyst_Forms_Validator::build_response(false, 'Your form has no notifications. Without any notifications, your form will only save responses to the Entries database.', self::LEVEL_WARNING); } } return $responses; } /** * Response builder, just keeps code cleaner. */ public static function build_response($valid, $message = '', $level = 0, $dismissable = false) { return array( 'valid' => $valid, 'message' => $message, 'level' => $level, 'level_str' => Alchemyst_Forms_Validator::level_as_string($level), 'dismissable' => $dismissable ); } /** * Translate constant into string. */ public static function level_as_string($level) { switch ($level) { case 0: return 'success'; case 1: return 'info'; case 2: return 'warning'; case 3: return 'error'; default: return 'error'; } } } class Alchemyst_Forms_Validator_Methods_Type { const LEVEL_SUCCESS = 0; const LEVEL_INFO = 1; const LEVEL_WARNING = 2; const LEVEL_ERROR = 3; } /** * Default validator methods. * Written in such a way that all class methods within this class are called. * * Can be extended: * class My_Alchemyst_Forms_Validator_Methods extends Alchemyst_Forms_Validator_Methods { *your new methods* } * add_filter('_alchemyst-forms:validator-class', 'My_Alchemyst_Forms_Validator_Methods'); * * All functions are passed the following * @param $post_id - The post_id associated with this contact form. * @param $cform_code - The raw HTML for the contact form. * @param $dom - The loaded Dom object with paquettg/PHPHtmlParser */ class Alchemyst_Forms_Validator_Methods extends Alchemyst_Forms_Validator_Methods_Type { /** * No