diff --git a/site_verify.admin.inc b/site_verify.admin.inc index 732f999..5bd5550 100644 --- a/site_verify.admin.inc +++ b/site_verify.admin.inc @@ -176,6 +176,12 @@ function site_verify_edit_form($form, &$form_state, $record = array(), $engine = function site_verify_validate_file($form, &$form_state) { $values = &$form_state['values']; + if (!empty($values['meta'])) { + if (!site_validate_meta_tag($values['meta'])) { + form_set_error('meta', t('The meta tag "@tag" is not valid. View the w3schools example', array('@tag' => $values['meta']))); + } + } + // Import the uploaded verification file. $validators = array('file_validate_extensions' => array()); if ($file = file_save_upload('file_upload', $validators, FALSE, FILE_EXISTS_REPLACE)) { @@ -200,6 +206,33 @@ function site_verify_validate_file($form, &$form_state) { } /** + * Helper function to validate meta tags + * @param string $string + * The meta tag string to validate. + * @return boolean + * A flag to indicate if validation passed. + */ +function site_validate_meta_tag($string) { + $doc = new DOMDocument(); + @$doc->loadHTML($string); + $metas = $doc->getElementsByTagName('meta'); + + if ($metas->length length; $i++) { + $meta = $metas->item($i); + foreach($meta->attributes as $attribute_name => $attribute_node) { + if (!empty($attribute_name) && empty($attribute_node->nodeValue)) { + return FALSE; + } + } + } + + return TRUE; +} +/** * Submission callback; send form to the next step or save the verification. */ function site_verify_edit_form_submit($form, &$form_state) {