<?php namespace ProcessWire;

/**
 * ProcessWire E-Mail Fieldtype
 *
 * Fieldtype for holding an email address. 
 *
 * For documentation about the fields used in this class, please see:  
 * /wire/core/Fieldtype.php
 * 
 * ProcessWire 3.x (development), Copyright 2015 by Ryan Cramer
 * https://processwire.com
 *
 *
 */


class FieldtypeEmail extends FieldtypeText {

	public static function getModuleInfo() {
		return array(
			'title' => 'E-Mail',
			'version' => 100,
			'summary' => 'Field that stores an e-mail address',
			);
	}

	public function getInputfield(Page $page, Field $field) {
		$inputfield = $this->modules->get('InputfieldEmail'); 
		$inputfield->class = $this->className();
		return $inputfield; 
	}

	public function sanitizeValue(Page $page, Field $field, $value) {
		$value = filter_var($value, FILTER_SANITIZE_EMAIL); 
		$value = filter_var($value, FILTER_VALIDATE_EMAIL); 
		return $value; 
	}

	public function getDatabaseSchema(Field $field) {
		$schema = parent::getDatabaseSchema($field); 
		$schema['data'] = "varchar(250) NOT NULL default ''";
		return $schema;
	}


	
}


