MiKe42 Posted February 14, 2011 Share Posted February 14, 2011 I'm trying to prevent clients from having duplicate names in WHMCS because of a third-party application we use. So far I've tried adding a hook to ClientDetailsValidation but I can't prevent the data from ever being changed. For instance, check out this proof-of-concept code (it's not supposed to prevent duplicates yet): add_hook("ClientDetailsValidation",0,"checkDuplicateNames",""); function checkDuplicateNames() { global $errormessage; $errormessage.="<li>Error!</li>"; } This shows an error message, but the data is always changed. I've also tried returning false or unsetting the $_POST variables but I can't seem to prevent the user details from changing. What am I missing? 0 Quote Link to comment Share on other sites More sharing options...
MiKe42 Posted February 18, 2011 Author Share Posted February 18, 2011 Any idea at all? 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted February 18, 2011 Share Posted February 18, 2011 All your doing there is adding "Error!" to the $errormessage variable whether it is correct or not. You will need to do a DB lookup on tblclients for the name that was entered and if the same as an existing then show the error. 0 Quote Link to comment Share on other sites More sharing options...
MiKe42 Posted February 18, 2011 Author Share Posted February 18, 2011 All your doing there is adding "Error!" to the $errormessage variable whether it is correct or not. You will need to do a DB lookup on tblclients for the name that was entered and if the same as an existing then show the error. Yes, I am aware of that. It's just test code. The problem is that I can't prevent changes, so writing the database query code right now wouldn't be of any help. I need to know what to do so I can prevent changes, because setting the error message doesn't prevent them at all. What variable do I need to change so that the new user info doesn't commit to the database? 0 Quote Link to comment Share on other sites More sharing options...
sparky Posted February 18, 2011 Share Posted February 18, 2011 Your looking for duplicate names, so is that not obvious? 0 Quote Link to comment Share on other sites More sharing options...
MiKe42 Posted February 18, 2011 Author Share Posted February 18, 2011 Your looking for duplicate names, so is that not obvious? I think I'm not getting my point across... When a client goes to the page where he can change his details, he might change his name, for instance. My function gets called because of the hook, so I have an opportunity to validate if his name is duplicated. The problem is not finding if the name is a duplicate. The problem is how do I tell WHMCS to discard the changes the client made. I can output an error message (that's what I do in that code), but the changes to the user details are still made. Is there another global variable that I am unaware of? Maybe a "global $errors"? How do I prevent the modifications the user made from actually happening? If I can only output an error message and not prevent the changes from happening (like it's happening now), I can't prevent duplicates in the future. 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted March 2, 2011 Share Posted March 2, 2011 Try changing your code from this: add_hook("ClientDetailsValidation",0,"checkDuplicateNames",""); to this: add_hook("ClientDetailsValidation",1,"checkDuplicateNames",""); this works for me and brings up an error message and stops the edit: function verify_email_doesnt_exist_in_kayako($vars) { global $errormessage; $errormessage .= "<li>The e-mail address you have entered already exists in our system.</li>"; return false; } add_hook("ClientDetailsValidation",1,"verify_email_doesnt_exist_in_kayako"); 0 Quote Link to comment Share on other sites More sharing options...
jason.burst.net Posted March 1, 2013 Share Posted March 1, 2013 I know this is old however this appears to still happen. The fix is simple, set the $_POST variable you don't want to be updated to a blank string. For example: $_POST['firstname'] = ''; 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.