Пример #1
0
 /**
  * Validates element.
  * 
  * @param type $element 
  */
 public function validateElement(&$element)
 {
     $check = Wpcf_Validate::check($element['#validate'], $element['#value']);
     if (isset($check['error'])) {
         $this->_errors = true;
         $element['#error'] = $check['message'];
     }
 }
Пример #2
0
/**
 * Adds validation box.
 * 
 * @param type $name
 * @param string $field
 * @param type $form_data
 * @return type 
 */
function wpcf_admin_fields_form_validation($name, $field, $form_data = array())
{
    $form = array();
    if (isset($field['validate'])) {
        $form['validate-table-open'] = array('#type' => 'markup', '#markup' => '<table class="wpcf-fields-form-validate-table" ' . 'cellspacing="0" cellpadding="0"><thead><tr><td>' . __('Validation', 'wpcf') . '</td><td>' . __('Error message', 'wpcf') . '</td></tr></thead><tbody>');
        // Process methods
        foreach ($field['validate'] as $k => $method) {
            // Set additional method data
            if (is_array($method)) {
                $form_data['data']['validate'][$k]['method_data'] = $method;
                $method = $k;
            }
            if (!Wpcf_Validate::canValidate($method) || !Wpcf_Validate::hasForm($method)) {
                continue;
            }
            $form['validate-tr-' . $method] = array('#type' => 'markup', '#markup' => '<tr><td>');
            // Get method form data
            if (Wpcf_Validate::canValidate($method) && Wpcf_Validate::hasForm($method)) {
                $field['#name'] = $name . '[' . $method . ']';
                $form_validate = call_user_func_array(array('Wpcf_Validate', $method . '_form'), array($field, isset($form_data['data']['validate'][$method]) ? $form_data['data']['validate'][$method] : array()));
                // Set unique IDs
                foreach ($form_validate as $key => $element) {
                    if (isset($element['#type'])) {
                        $form_validate[$key]['#id'] = $element['#type'] . '-' . mt_rand();
                    }
                    if (isset($element['#name']) && strpos($element['#name'], '[message]') !== FALSE) {
                        $before = '</td><td>';
                        $after = '</td></tr>';
                        $form_validate[$key]['#before'] = isset($element['#before']) ? $element['#before'] . $before : $before;
                        $form_validate[$key]['#after'] = isset($element['#after']) ? $element['#after'] . $after : $after;
                    }
                }
                // Join
                $form = $form + $form_validate;
            }
        }
        $form['validate-table-close'] = array('#type' => 'markup', '#markup' => '</tbody></table>');
    }
    return $form;
}
Пример #3
0
 /**
  * Inits messages.
  */
 private static function _set_messages()
 {
     // Set outside in /admin.php
     self::$messages = wpcf_admin_validation_messages();
 }
 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 public function form_validation($name, $field, $form_data = array())
 {
     if (!isset($field['validate'])) {
         return array();
     }
     $form = array();
     // Process methods
     foreach ($field['validate'] as $k => $method) {
         // Set additional method data
         if (is_array($method)) {
             $form_data['data']['validate'][$k]['method_data'] = $method;
             $method = $k;
         }
         if (!Wpcf_Validate::canValidate($method) || !Wpcf_Validate::hasForm($method)) {
             continue;
         }
         // Get method form data
         if (Wpcf_Validate::canValidate($method) && Wpcf_Validate::hasForm($method)) {
             $field['#name'] = $name . '[' . $method . ']';
             $form_validate = call_user_func_array(array('Wpcf_Validate', $method . '_form'), array($field, isset($form_data['data']['validate'][$method]) ? $form_data['data']['validate'][$method] : array()));
             // Set unique IDs
             $is_first = true;
             foreach ($form_validate as $key => $element) {
                 if (isset($element['#type'])) {
                     $form_validate[$key]['#id'] = $element['#type'] . '-' . wpcf_unique_id(serialize($element));
                 }
                 if ($is_first && isset($element['#pattern'])) {
                     $is_first = false;
                     $form_validate[$key]['#pattern'] = preg_replace('/<tr>/', '<tr class="wpcf-border-top">', $element['#pattern']);
                 }
             }
             // Join
             $form = $form + $form_validate;
         }
     }
     return $form;
 }