Jump to content

Displaying message to the client from a hook


tsgeoff

Recommended Posts

Hi all.

 

I'm a newcomer to WHMCS, so please forgive me if this is obvious. I have tried searching, but cannot find a solution.

 

My question is as follows:

 

My application consists of two independent systems - with the user accounts synchronised between them. Currently, I'm making use of the ClientEdit hook to update the non-WHMCS system with the client's new details every time the client's details are updated. However, due to the fact this is a third-party API that is called (via HTTP request), there is the chance for failure.

 

So how, from the hook, would I be able to display an error or other message to the client, alerting them to the fact that their update has actually failed? Currently, I cannot set such a message and as such (regardless of whether my third-party integration actually happened), a success message is displayed.

 

Any help in this regard would really be helpful!

 

Thanks,

Geoff

Link to comment
Share on other sites

Hey James.

 

Thanks for the response. The fact that it is $errormessage to me implies it will indicate an error. Is there any way to indicate anything else - such as a warning or success message?

 

I'm only needing to indicate an error message at the moment - but it might be good to know for future use.

Link to comment
Share on other sites

The fact that it is $errormessage to me implies it will indicate an error.

Yes, you'd use $errormessage to return an error message.

 

Is there any way to indicate anything else - such as a warning or success message?

 

I'm only needing to indicate an error message at the moment - but it might be good to know for future use.

For the most part, that depends upon the specific hook point and page. For example, within the clientareadetails.tpl, the changes saved successfully message is displayed when $successful is set. You could either update the appropriate language string to include text relating to your external update, you could define an entirely new smarty variable and display your own custom success message for the remote update in addition to the standard one, etc.

Edited by WHMCS JamesX
Link to comment
Share on other sites

Ah, okay. I see.

 

To be honest - I completely forgot about the fact that the area is templated - so I can update my template to whatever I want. However, this is where another issue coming in (additionally, updating $errormessage

 

According to the WHMCS documentation, there are no return variables for the ClientEdit hook. Which is fine - if I was able to find out how to send custom variables through the template.

 

I've done some digging around with dumping out declared classes and objects, and I can't seem to find any way in which I would be able to send a custom variable through to the template.

 

Perhaps I've overlooked something? Have you ever needed to do something like this?

 

EDIT: So, I was playing around some more, and came across a variable called [highlight]$smartyvalues[/highlight], which seems to contain the values.

 

function hook_name ($vars)
{
   global $smartyvalues;
   $smartyvalues['myvarname'] = 'foo'; // {$myvarname} now becomes available in your template.
}

 

This can be used to override the error messages, and any variables that may have already been set by WHMCS (such as the {$success} or {$errormessage} variables in the template - I found that global $errormessage didn't work for me).

 

I thought I might include this information in case anyone came across the same issue / need as I did.

Edited by tsgeoff
Found more information
Link to comment
Share on other sites

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