--- emailpage.module_original	2006-05-10 00:26:39.000000000 +0200
+++ emailpage.module	2006-05-23 19:07:08.000000000 +0200
@@ -149,6 +149,19 @@
 }
 /* }}} */
 
+/* {{{ _emailpage_main_validate */
+/**
+ * Implementation of FormsAPI _validate()
+ */
+function _emailpage_main_validate($form_id, $form_values) {  if ($form_values['name'] == '') {  if(!valid_email_address($form_values['emailpage_main']['recipient'])) {
+    form_set_error(
+      'emailpage_main][recipient',
+      t('The email address supplied ("%email") appears to be invalid',array('%email' => $form_values['emailpage_main']['recipient']))
+    );
+  }
+  }}
+/* }}} */
+
 /* {{{ _emailpage_main_submit */
 /**
  * Implementation of FormsAPI _submit()
@@ -158,11 +171,6 @@
   global $base_url;
 
   $to = $form_values['emailpage_main']['recipient'];
-  $name = $user->name;
-
-  if(!valid_email_address($to)) {
-    return '<p/>' . t('The email address supplied "') . $to . t('" appears to be invalid');
-  }
 
   if($user->uid == 0) { // anon user
     if(!_emailpage_local_settings('allow_anon')) {
@@ -176,6 +184,7 @@
   }
   else {
     $from = $user->mail;
+    $name = $user->name;
   }
 
   $subject = str_replace('%someone', $name, _emailpage_local_settings('subject'));
@@ -528,5 +537,3 @@
   return $a;
 }
 /* }}} */
-
-?>
