Title: Non required E-mail doesn&#039;t validate correctly
Last modified: August 22, 2016

---

# Non required E-mail doesn't validate correctly

 *  Resolved [cpaprotna](https://wordpress.org/support/users/cpaprotna/)
 * (@cpaprotna)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/)
 * I have added extra e-mail fields to my user profile with the advanced custom 
   field plugin. I can modify the fields find in the wordpress dashboard.
 * I added the following code to my theme function.php file:
 *     ```
       add_filter( 'cuar/core/user-profile/get_profile_fields', 'pro_image_add_profile_fields');
       function pro_image_add_profile_fields($default_fields){ 
   
       $default_fields = array(
       				'account_details'	=> new CUAR_HeaderField( 'account_details', array(
       						'label'			=> __( 'Account details', 'cuar' )
       					) ),
   
       				'user_login' 		=> new CUAR_TextField( 'user_login', new CUAR_UserStorage(), array(
       						'label'			=> __( 'Username', 'cuar' ),
       						'readonly'		=> true,
       						'inline_help'	=> __( 'Your username cannot be changed.', 'cuar' ),
       						'required'		=> true,
       					) ),
   
       				'user_email' 		=> new CUAR_EmailField( 'user_email', new CUAR_UserStorage(), array(
       						'label'			=> __( 'Primary email', 'cuar' ),
       						'required'		=> true,
       					) ),
   
       				'secondary_e-mail' 		=> new CUAR_EmailField( 'secondary_e-mail', new CUAR_UserMetaStorage(), array(
       						'label'			=> __( 'Secondary email', 'cuar' ),
       						'required'		=> false,
       					) ),					
   
       				'third_e-mail' 		=> new CUAR_EmailField( 'third_e-mail', new CUAR_UserMetaStorage(), array(
       						'label'			=> __( 'Third email', 'cuar' ),
       						'required'		=> false,
       					) ),
       				);
       	return $default_fields;
       }
       ```
   
 * When I tried to remove the value in the Third email field, I kept getting an 
   error that the field was not a valid e-mail. Is there something I need to do 
   to make sure that when it saves, if the value is now empty it will just put an
   empty value in the database?
 * [https://wordpress.org/plugins/customer-area/](https://wordpress.org/plugins/customer-area/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Vincent Mimoun-Prat](https://wordpress.org/support/users/vprat/)
 * (@vprat)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/#post-5345060)
 * Hmmm. that may be a bug in the validation. I will check and update when I can(
   currently quite busy). If you are fine with PHP, you could also checkout the 
   plugin source code from GitHub and try to see what’s going on.
 * [https://github.com/marvinlabs/customer-area](https://github.com/marvinlabs/customer-area)
 *  Thread Starter [cpaprotna](https://wordpress.org/support/users/cpaprotna/)
 * (@cpaprotna)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/#post-5345095)
 * I modified the file \customer-area\includes\core-classes\object-meta\validation\
   email-validation.class.php
 * and changed the validate function to:
 *     ```
       public function validate( $label, $value ) {
       		$parent_val = parent::validate( $label, $value );
       		if ( $parent_val!==TRUE ) return $parent_val;
       		if (!$this->required && empty($value)) return TRUE;
       		if ( !is_email( $value ) ) return sprintf( __('%1$s is not a valid email address.', 'cuar'), $label );
   
       		return TRUE;
       	}
       ```
   
 *  Plugin Contributor [Vincent Mimoun-Prat](https://wordpress.org/support/users/vprat/)
 * (@vprat)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/#post-5345157)
 * Thanks, it would be great if you could submit a pull request on GitHub for that
   fix.
 *  Thread Starter [cpaprotna](https://wordpress.org/support/users/cpaprotna/)
 * (@cpaprotna)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/#post-5345164)
 * I’ll try, I’ve never used GitHub before…
 *  Plugin Contributor [Vincent Mimoun-Prat](https://wordpress.org/support/users/vprat/)
 * (@vprat)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/#post-5345168)
 * It worked. Next time it would be better if you could submit the pull request 
   against the “develop” branch instead of the “master” branch.
 * Thanks a lot

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Non required E-mail doesn't validate correctly’ is closed to new replies.

 * ![](https://ps.w.org/customer-area/assets/icon-256x256.png?rev=1288039)
 * [WP Customer Area](https://wordpress.org/plugins/customer-area/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/customer-area/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/customer-area/)
 * [Active Topics](https://wordpress.org/support/plugin/customer-area/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/customer-area/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/customer-area/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Vincent Mimoun-Prat](https://wordpress.org/support/users/vprat/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/non-required-e-mail-doesnt-validate-correctly/#post-5345168)
 * Status: resolved