Skip Navigation

[Resolved] Getting a "Passwords don't match" error for generic fields type=email

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1280573
Screen Shot 2019-06-30 at 9.44.07 PM.png

I am trying to:
Create a "Change My Email" form.

Link to a page where the issue can be seen:
hidden link

I expected to see:
If new email and new email again fields don't match, should be "Emails don't match".

Instead, I got:
"Passwords don't match".

I don't know where that message is coming from. How do I control that?

My CRED form:

[creduserform]	
	[cred_field field='form_messages' class='alert alert-warning']
	<div style="width:90%;margin-bottom:2rem;font-size:1.2rem;color:#666;">
           <strong>Username: <span style="color:#06a">[wpv-user field="user_login"]</span></strong>
           <br />
	</div>
	<div style="width:90%;margin-bottom:2rem;font-size:1.2rem;color:#666;">
           <strong>Your current email address is: &nbsp; <span style="color:#06a">[wpv-current-user info='email']</span></strong>
        </div>
        <div id="newEmailAddr" style="width:50%;margin-bottom:2rem;">
           <label>Enter New Primary Email Address *</label>
           [cred_generic_field type='email' field='new_user_email_temp' id='new_user_email_temp']
		{
		"required":1,
		"validate_format":1,
		"default":""
		}
           [/cred_generic_field]
           <span style="font-size:1rem;color:#666;">* Main email used for this account.</span>
	</div>
	<div id="newEmailAddrConfirm" style="width:50%;margin-bottom:2rem;">
        <label>Confirm New Primary Email Address</label>
		[cred_generic_field type='email' field='new_user_email_temp_confirm' id='new_user_email_temp_confirm']
		{
		"required":1,
		"validate_format":1,
		"default":""
		}
		[/cred_generic_field]
	</div>

	<div class="form-group" style="display:none; width:16%;margin-bottom:3rem;">
		<label>Member Profile ID</label>
		[cred_field field='member-profile-id' force_type='field' class='form-control' output='']
	</div>

	[cred_field field='form_submit' output='' value='Submit' class='btn btn-primary btn-lg']

[/creduserform]

NOTE that this website is more than 5 years old and I started with a very early version of types/views that did not support User forms. So, I had to create my own way. I created a CPT to act like a profile. Then, in the WP User, I created a custom field that references the post_id of the member's profile CPT. So, when a member updates their email, I need to update it in both places. Yes, I know it's a kludge, but it's been working fine that way for 5+ years, and it would be a LOT of work to change it in every View and Content Template. So, forgive me.

Also, remember to access this staging site:
flywheel
cnsvi333_%_$*9

My PHP code:

// Change My Email address (for current user, from Edit My Profile screens)
add_action('cred_save_data', 'change_my_email_addr',20,2);
function change_my_email_addr($post_id,$form_data) {
   $current_user = wp_get_current_user();		// we beed the login (username) to use wp_insert_user()
   $user_id = $current_user->ID;				// and the ID

   if ($form_data['id'] == 32684) {	// is this the change my email form?
    	$new_email = esc_attr( $_POST['new_user_email_temp'] );   // user_email
    	$usermeta_member_profile_id = $_POST['wpcf-member-profile-id'];
    	$post_id = $usermeta_member_profile_id;

//      echo ('<br/> USER ID = ' . $user_id . ', NEW EMAIL = ' . $new_email . ', MBR-PROF-ID = ' . $usermeta_member_profile_id . '<br/>');
//      die;

        // store it to the CNSV member profile
        update_post_meta($post_id, 'wpcf-email', $new_email);

        // update it in the WP user
        add_filter( 'send_email_change_email', '__return_false' );  // first, disable email notice of change
        if (email_exists( $new_email )) {
            // Email exists, do not update value.
            echo ('<br/><br/><br/> ERROR: THAT EMAIL ALREADY EXISTS! <br/>');
        } else {
             $args = array(
             'ID'         => $user_id,
             'user_email' => $new_email
             );
            wp_update_user( $args );
        }
    }
}
#1280635

Hello,

The action hook cred_save_data is triggered after data is saved, and it won't be able to prevent email from sending.

In your case, I suggest you try another filter hook "cred_form_validate", it will be able to trigger before data is saved, and if it is failed to pass the validation, as a result, email notification won't be sent.

See our document:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
This hook provides custom validation for form fields.

#1286901

Oops! I am not finished with this issue yet. Just got back from vacation.

Thanks,
Jeff

#1287225

I have re-open this thread, please let me know if you still need assistance for it, thanks