You are here

function features_export_form_validate_field in Features 7.2

Same name and namespace in other branches
  1. 6 features.admin.inc \features_export_form_validate_field()
  2. 7 features.admin.inc \features_export_form_validate_field()

Form API callback: Validates a project field.

This function is assigned as an #element_validate callback in features_export_form().

Parameters

array $element: Form element with '#type' => 'textfield'.

array $form_state: Form state.

1 string reference to 'features_export_form_validate_field'
features_export_form in ./features.admin.inc
Form builder for features export form.

File

./features.admin.inc, line 901
Forms for Features admin screens.

Code

function features_export_form_validate_field($element, &$form_state) {
  switch ($element['#name']) {
    case 'project_status_url':
      if (!empty($element['#value']) && !valid_url($element['#value'])) {
        form_error($element, t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array(
          '%url' => $element['#value'],
        )));
      }
      break;
    case 'version':
      preg_match('/^(?P<core>\\d+\\.x)-(?P<major>\\d+)\\.(?P<patch>\\d+)-?(?P<extra>\\w+)?$/', $element['#value'], $matches);
      if (!empty($element['#value']) && !isset($matches['core'], $matches['major'])) {
        form_error($element, t('Please enter a valid version with core and major version number. Example: @example', array(
          '@example' => '7.x-1.0',
        )));
      }
      break;
  }
}