[[!FormIt? &customValidators=`ConfirmEmail` &validate=` nospam:blank, email:required:email, confirm_email:ConfirmEmail=^email^` &hooks=`[[!UpdateProfile? &useExtended=`0`]]` ]] <p>Current email: [[!+email]]</p> <div class="update-profile"> <div class="updprof-error">[[+error.message]]</div> [[+login.update_success:if=`[[+login.update_success]]`:is=`1`:then=`[[%login.profile_updated? &namespace=`login` &topic=`updateprofile`]]`]] <form class="form" action="[[~[[*id]]]]" method="post"> <input type="hidden" name="nospam" value="" /> <label for="email">New [[!%login.email]] </label> <input type="text" name="email" id="email" value="[[!+fi.email]]" /> <span class="error">[[!+fi.error.email]]</span><br /> <label for="confirm_email">Confirm New Email: </label> <input type="text" name="confirm_email" id="confirm_email" value="[[!+fi.confirm_email]]" /> <span class="error">[[!+fi.error.confirm_email]]</span><br /> <br class="clear" /> <div class="form-buttons"> <input type="submit" name="login-updprof-btn" value="[[!%login.update_profile]]" /> </div> </form> </div>
This question has been answered by nepheus. See the first response.
This might be a bit hacky but it might actually work IDK it's just a theory, why don't you just use FormIt to validate the email and then have it run the UpdateProfile code on a success message that way it will only update the profile after it has passed the validation.
You might need to use FormIt store to save the email value and then FormItRetriever in the success message to set the email value and then run the UpdateProfile code.
I'm also trying to help you, but I don't know why I just can't make the UpdateProfile snippet to work, it doesn't throw any errors. The other snippets just work fine. Have a sleep, tomorrow I'll try again.
recheckEmail snippet
<?php $modx->log(MODX::LOG_LEVEL_ERROR, 'processing hook for confirm email'); //begin debug $modx->log(MODX::LOG_LEVEL_ERROR, $hook->getValue('email')); //test get value $email = $hook->getValue('email'); $confirm_email = $hook->getValue('confirm_email'); $user = $login->getUserByField('username', $modx->getLoginUserName()); $modx->log(MODX::LOG_LEVEL_ERROR, $user->get('email')); //test getting user email //check if email is changed? if (strcmp($email, $user->get('email'))==0) return true; //no change, so just return the form without any errors //else compare and validate the confirm_email field if (strcmp($email,$confirm_email)==0) //validated equal fields return true; else{ $hook->addError('confirm_email','Please confirm your email'); return false; }
[[!UpdateProfile? &validate=`fullname:required,email:required:email`&preHooks=`recheckEmail`&useExtended=`0`]]
<label for="confirm_email">[[!%login.confirm_email]] <span class="error">[[+error.confirm_email]]</span> </label> <input type="text" name="confirm_email" id="email" value="[[+confirm_email]]" />
I've done a custom snippet to work with UpdateProfile snippet, using its preHooks option. You can have a look as below, this is tested under my setup and it works just fine:
Quote from: nepheus at Apr 12, 2013, 07:57 AMI've done a custom snippet to work with UpdateProfile snippet, using its preHooks option. You can have a look as below, this is tested under my setup and it works just fine:
Wow! Thank you so much for the trouble!
Right now I'm dealing with some server issues after I tried to upgrade my MODX version, but as soon as I have it running again I'll be sure to try this too.
It's all in the name of learning, after all. =)
Thanks a lot for the help!