@charset "UTF-8";

/*
Theme Name: kingscollege
*/

/**
 * SETTINGS
 * File-header..........The file header for the themes style.css file.
 * Fonts................Any font files, if the project needs specific fonts.
 * Global...............Project-specific, globally available variables.
 *
 * TOOLS
 * Functions............Global functions.
 * Mixins...............Global mixins.
 *
 * GENERIC
 * Normalize.css........Normalise browser defaults.
 * Breakpoints..........Mixins and variables for responsive styles
 * Vertical-margins.....Vertical spacing for the main components.
 * Reset................Reset specific elements to make them easier to style in other contexts.
 * Clearings............Clearings for the main components.
 *
 * ELEMENTS
 * Blockquote...........Default blockquote.
 * Forms................Element-level form styling.
 * Headings.............H1–H6
 * Links................Default links.
 * Lists................Default lists.
 * Media................Images, Figure, Figcaption, Embed, iFrame, Objects, Video.
 *
 * BLOCKS
 * Audio................Specific styles for the audio block.
 * Button...............Specific styles for the button block.
 * Code.................Specific styles for the code block.
 * Columns..............Specific styles for the columns block.
 * Cover................Specific styles for the cover block.
 * File.................Specific styles for the file block.
 * Gallery..............Specific styles for the gallery block.
 * Group................Specific styles for the group block.
 * Heading..............Specific styles for the heading block.
 * Image................Specific styles for the image block.
 * Latest comments......Specific styles for the latest comments block.
 * Latest posts.........Specific styles for the latest posts block.
 * Legacy...............Specific styles for the legacy gallery.
 * List.................Specific styles for the list block.
 * Media text...........Specific styles for the media and text block.
 * Navigation...........Specific styles for the navigation block.
 * Paragraph............Specific styles for the paragraph block.
 * Pullquote............Specific styles for the pullquote block.
 * Quote................Specific styles for the quote block.
 * Search...............Specific styles for the search block.
 * Separator............Specific styles for the separator block.
 * Table................Specific styles for the table block.
 * Verse................Specific styles for the verse block.
 * Video................Specific styles for the video block.
 * Utilities............Block alignments.
 *
 * COMPONENTS
 * Header...............Header styles.
 * Footer...............Footer styles.
 * Comments.............Comment styles.
 * Archives.............Archive styles.
 * 404..................404 styles.
 * Search...............Search styles.
 * Navigation...........Navigation styles.
 * Footer Navigation....Footer Navigation styles.
 * Pagination...........Pagination styles.
 * Single...............Single page and post styles.
 * Posts and pages......Misc, sticky post styles.
 * Entry................Entry, author biography.
 * Widget...............Widget styles.
 * Editor...............Editor styles.
 *
 * UTILITIES
 * A11y.................Screen reader text, prefers reduced motion etc.
 * Color Palette........Classes for the color palette colors.
 * Editor Font Sizes....Editor Font Sizes.
 * Measure..............The width of a line of text, in characters.
 */

/* Categories 01 to 03 are the basics. */

add_filter( 'wpcf7-text*', 'alphanumeric_validation_filter', 20, 2 );

function alphanumeric_validation_filter( $result, $tag ) {
  $tag = new WPCF7_FormTag($tag);
  $name = $tag->name;
  $value = isset( $_POST[$name] ) ? trim( $_POST[$name] ) : '';

  // Check if the field is the one named 'your-name'
  if ( 'studentname ' == $name ) {
    // Regex for letters, numbers, and spaces
    if ( ! preg_match( '/^[a-zA-Z ]+$/', $value ) ) {
      $result->invalidate( $tag, 'Only alphanumeric characters and spaces are allowed.' );
    }
  }

  return $result;
}

add_filter( 'wpcf7_validate_email*', 'custom_email_domain_validation_filter', 20, 2 );

function custom_email_domain_validation_filter( $result, $tag ) {
    $tag = new WPCF7_FormTag( $tag );
    $name = $tag->name;

    // Check if the field is the one named 'your-email'
    if ( 'email' == $name ) {
        $email = isset( $_POST[$name] ) ? trim( $_POST[$name] ) : '';
        $allowed_domains = array( 'gmail.com', 'hotmail.com', 'yahoo.com', 'rediffmail.com','kingscollege-uk-ncr.com' );

        // Use PHP to split the email and get the domain part
        $email_domain = substr( strrchr( $email, "@" ), 1 );

        // Check if the domain is not in the allowed list
        if ( ! in_array( $email_domain, $allowed_domains ) ) {
            $result->invalidate( $tag, 'Please use an email from an allowed provider (e.g., gmail.com, hotmail.com, yahoo.com, rediffmail.com).' );
        }
    }

    return $result;
}

