Jump to content

Hook won't output my 'return' on submitticket.php


Recommended Posts

I'm having trouble returning a string using ClientAreaPageSubmitTicket. If I use AdminAreaViewTicketPage, the div is shown just fine when viewing a ticket as an admin.

 <?php
add_hook('ClientAreaPageSubmitTicket', 1, function($vars) {
	return '<div class="alert alert-info alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Check <b><a href="/client/serverstatus.php">serverstatus</a></b> before submitting a new ticket</div>';
    
});

Any reason why this doesn't work?

Link to comment
Share on other sites

1 hour ago, DennisMidjord said:

Any reason why this doesn't work?

because ClientAreaPageSubmitTicket returns a Smarty array, not a string - so you effectively have two simple choices (there would be other complicated ones too!) - either rewrite the hook to return an array...

<?php

# Submit Ticket String Hook
# Written by brian!

function submit_ticket_string_hook($vars){
	
	$submitstring = '<div class="alert alert-info alert-dismissible"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>Check <b><a href="/client/serverstatus.php">serverstatus</a></b> before submitting a new ticket</div>';
	return array("submitstring" => $submitstring);

}
add_hook("ClientAreaPageSubmitTicket", 1, "submit_ticket_string_hook");

... but then you'd have to edit the template to decide where to output that array and add {$submitstring} there... or just edit the template and add your code to it directly.

given that you're going to have to edit the template anyway going down this road, you might as well just edit the template.

Link to comment
Share on other sites

Hi Dennis,

the thing about hooks returning strings is that it only works when the template has been designed to expect it - some of them have, most haven't... even if your original hook did return a string, it wouldn't know exactly where to output it in the template - nor could you tell it in the hook.

I suppose that you could use one of the headoutput hooks to add your banner along the page, but I wouldn't think that it would look particularly impressive... 😧

IYopJFA.png

I don't know where you wanted to output the alert, but there would be alternatives to returning a string in a hook or editing the template...

  1. use a Language Override and change the header text used on the support page...
    $_LANG['supportticketsheader'] = "If you can't find a solution to your problems in our knowledgebase, you can submit a ticket by selecting the appropriate department below.<br><div class=\"alert alert-info alert-dismissible\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>Check <b><a href=\"serverstatus.php\">serverstatus</a></b> before submitting a new ticket</div>";

    ogyZYLm.png
    if memory serves, you only use Danish & English on your site, so you should only need to create an override for each of those languages - and they shouldn't be removed / overwritten during a WHMCS update.

  2. you can open a bootstrap modal window on the page using a hook (technically 2 hooks in the same file)...
    A7WEcXb.png
    it uses language overrides were possible (obviously not your string!)... the hook code is just a slightly varied version of the one i demo'd two years ago in the thread below and still works fine in v7.7 (or earlier) in the "Six" template...


    given time I could probably think of other solutions, but for your situation, that Language Overrides option might be the quickest one, without editing the template, that is the closest to what you wanted to do in the hook. thanks.png

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