Jump to content

Validating client information


MiKe42

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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");

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated