function wpsc_validate_form($form_args, &$validated_array = false) { if (!is_array($validated_array)) { $validated_array =& $_POST; } $error = new WP_Error(); $a =& $error; if (!isset($form_args['fields'])) { $valid = null; } else { $valid = true; } $form = $form_args['fields']; foreach ($form as $props) { // Handle custom fields. if (!isset($props['fields'])) { $props['fields'] = $props; } foreach ($props['fields'] as $prop) { if (empty($prop['rules'])) { continue; } $prop = _wpsc_populate_field_default_args($prop); $field = $prop['name']; $rules = $prop['rules']; if (is_string($rules)) { $rules = explode('|', $rules); } $value = wpsc_submitted_value($field, '', $validated_array); foreach ($rules as $rule) { if (function_exists($rule)) { $value = call_user_func($rule, $value); continue; } if (preg_match('/([^\\[]+)\\[([^\\]]+)\\]/', $rule, $matches)) { $rule = $matches[1]; $matched_field = $matches[2]; $matched_value = wpsc_submitted_value($matched_field, null, $validated_array); $matched_props = isset($form[$matched_field]) ? $form[$matched_field] : array(); $error = apply_filters("wpsc_validation_rule_{$rule}", $error, $value, $field, $prop, $matched_field, $matched_value, $matched_props); } else { $error = apply_filters("wpsc_validation_rule_{$rule}", $error, $value, $field, $prop); } if (count($error->get_error_codes())) { break; } } } _wpsc_set_submitted_value($field, $value, $validated_array); } if (count($error->get_error_messages())) { $valid = $error; } return apply_filters('wpsc_validate_form', $valid); }
function _wpsc_get_field_output($field, $r) { $output = ''; $field = _wpsc_populate_field_default_args($field); if ($field['type'] == 'fieldset') { return _wpsc_get_fieldset_output($field, $r); } $before_field = apply_filters('wpsc_field_before', $r['before_field'], $field, $r); $before_field = sprintf($before_field, $field['id'], $field['class']); $output .= $before_field; $output .= apply_filters('wpsc_control_before', $r['before_controls'], $field, $r); $output .= apply_filters("wpsc_control_{$field['type']}", '', $field, $r); $output .= apply_filters('wpsc_control_after', $r['after_controls'], $field, $r); $output .= apply_filters('wpsc_field_after', $r['after_field'], $field, $r); return $output; }