function engagements_send_email_or_txt_form_validate

6.x engagements.module engagements_send_email_or_txt_form_validate($form, &$form_state)
1 string reference to 'engagements_send_email_or_txt_form_validate'
engagements_form_alter in modules/engagements/engagements.module
Implements hook_form_alter

File

modules/engagements/engagements.module, line 3056
This is the primary module file for the engagements module.

Code

function engagements_send_email_or_txt_form_validate($form, &$form_state) 
 {

  $values = $form_state ['values'];

  ////////
  // TODO: I am not sure I even need to get the cid here...  delete it?  
  $cid = NULL;
  if (isset($form_state ['content_object']) && is_object($form_state ['content_object'])) {
    $cid = $form_state ['content_object']->cid; // At this point, the content has already been saved, so we know its cid.
  }
  ////////


  $engagement_type = $values ['engagement_type'];

  $manual_entry = @trim(strtoupper($values ['manual_entry']));

  if ($engagement_type != 'email' && $engagement_type != 'txt_msg') {
    return; // we are not interested, harmlessly return.
  }

  $student_id = $values ['student_id'];
  $faculty_id = $values ['faculty_id'];
  $msg = $values ['engagement_msg'];

  $from_number = trim($values ['from_sms_phone']);

  $db = get_global_database_handler();

  if ($engagement_type == 'email' && $manual_entry != 'Y') {
    $student_email = fp_get_student_email($student_id);
    if (!filter_var($student_email, FILTER_VALIDATE_EMAIL)) { // take advantage of pho built-in email validator
      form_error('engagement_msg', t("Sorry, but the email provided for the student appears to be invalid."));
      return;
    }
  } // type == 'email'


  if ($engagement_type == 'txt_msg' && $manual_entry != 'Y') {

    $student_user_id = db_get_user_id_from_cwid($student_id, 'student');


    $temp = user_get_attribute($student_user_id, 'mobile_phone');
    $mobile_phone = engagements_convert_to_valid_phone_number(trim($temp));

    if (!$mobile_phone) {
      form_error('engagement_msg', t('Sorry, but the mobile phone number provided for the student appears to be invalid.'));
      return;
    }
  } // type == 'txt_msg'


}