• Resolved cpaprotna

    (@cpaprotna)


    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/

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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

    Thread Starter cpaprotna

    (@cpaprotna)

    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;
    	}

    Thanks, it would be great if you could submit a pull request on GitHub for that fix.

    Thread Starter cpaprotna

    (@cpaprotna)

    I’ll try, I’ve never used GitHub before…

    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.