You are here

function facebook_wall_settings_form_validate in Facebook Wall 7

FormAPI validation callback for facebook_wall_settings_form().

File

./facebook_wall.admin.inc, line 253
Contains the administrative functions of the Facebook Wall fetcher module.

Code

function facebook_wall_settings_form_validate(&$form, &$form_state) {

  // Removing token & time if app id change.
  if (stristr($form_state['values']['facebook_wall_app_id'], variable_get('facebook_wall_app_id')) == FALSE) {
    variable_del('facebook_wall_access_token');
    variable_del('facebook_wall_access_token_expiry');
    variable_del('facebook_wall_access_token_start');
    $form_state['values']['facebook_wall_access_token_temp'] = '';
  }
  if (isset($form_state['values']['facebook_wall_post_limit'])) {
    if (!is_numeric($form_state['values']['facebook_wall_post_limit'])) {
      form_set_error('facebook_wall_post_limit', t('FB wall post limit should be numeric'));
    }
    elseif ($form_state['values']['facebook_wall_post_limit'] < 1 || $form_state['values']['facebook_wall_post_limit'] > 999) {
      form_set_error('facebook_wall_post_limit', t('FB wall post limit should be between 1 to 999.'));
    }
  }
  $url = 'https://www.facebook.com/' . $form_state['values']['facebook_wall_page_url'];
  if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) {
    form_set_error('facebook_wall_page_url', t('FB page URL or user id is not a valid address.'));
  }
  if (isset($form_state['values']['facebook_wall_post_type_link'])) {
    if ($form_state['values']['facebook_wall_post_type_link'] == 0 && $form_state['values']['facebook_wall_post_type_photo'] == 0 && $form_state['values']['facebook_wall_post_type_status'] == 0 && $form_state['values']['facebook_wall_post_type_video'] == 0) {
      form_set_error('facebook_wall_post_type_status', t('Please select atleast one FB Wall post type.'));
    }
  }
  if (isset($form_state['values']['facebook_wall_width_option'])) {
    if ($form_state['values']['facebook_wall_width_option'] == 'relative-width') {
      if (isset($form_state['values']['facebook_wall_width_size_relative'])) {
        if (!is_numeric($form_state['values']['facebook_wall_width_size_relative'])) {
          form_set_error('facebook_wall_width_size_relative', t('FB wall post width should be numeric (don\'t include the % symbol).'));
        }
        if ($form_state['values']['facebook_wall_width_size_relative'] <= 0 || $form_state['values']['facebook_wall_width_size_relative'] > 100) {
          form_set_error('facebook_wall_width_size_relative', t('FB wall post width should be greater than 0% and less than 100%.'));
        }
      }
    }
    elseif ($form_state['values']['facebook_wall_width_option'] == 'pixel-width') {
      if (isset($form_state['values']['facebook_wall_width_size'])) {
        if (!is_numeric($form_state['values']['facebook_wall_width_size'])) {
          form_set_error('facebook_wall_width_size', t('FB wall post width should be numeric.'));
        }
        if ($form_state['values']['facebook_wall_width_size'] < 400 || $form_state['values']['facebook_wall_width_size'] > 800) {
          form_set_error('facebook_wall_width_size', t('FB wall post width should between 400px and 800px.'));
        }
      }
    }
  }
}