DennisHermannsen Posted June 17, 2019 Share Posted June 17, 2019 How would we go about creating a custom form in WHMCS? The form should only take one input (email address). When the client submits this, the value will be checked against the WHMCS database, and if a phone number is found, a ticket should be created containing the client's phone number. I can't seem to find a way for WHMCS to accept custom user input. Can't that be done? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 17, 2019 Share Posted June 17, 2019 27 minutes ago, DennisMidjord said: How would we go about creating a custom form in WHMCS? in two parts really - firstly, it's either going to be a html form embedded into an existing page/template, or it's going to be a custom page... i'm assuming that you know how to do either of these? the second part is the PHP side, which basically accepts the data posted to it by the above form, does your checks and opens a ticket if conditions are applicable... that check is basically going to be a query to the database (via capsule, models or whatever) that sees if the email submitted exists - if it does, then sees if there's a phone number assigned to that client and if so, runs the Open Ticket API to generate the ticket. you might find this video interesting as a basic walk-though to most of what you're trying to do - specifically the API side of things... it's not mine, but thought it would be quicker than posting a long explanation myself. 🙂 46 minutes ago, DennisMidjord said: The form should only take one input (email address). When the client submits this, the value will be checked against the WHMCS database, and if a phone number is found, a ticket should be created containing the client's phone number. when the client submits this email address, are they already logged in ? if so, you will already have access to that email address from existing available template variables - you'd also have access to their phone number (if they have one), so you could generate a hypertext link to submit a ticket in those circumstances without the need of a custom form. {if $clientsdetails.phonenumber}<a href="submitticket.php?step=2&deptid=1&subject={$clientsdetails.phonenumber}">{$LANG.navopenticket}</a>{/if} although maybe i'm missing the point of why you're trying to do this? 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted June 17, 2019 Author Share Posted June 17, 2019 (edited) Thanks for all your help @brian! - I'm really glad. You've helped me so much with various problems 🙂 It's going to be a custom page or embedded into the current 'submitticket.php' website. I haven't decided yet - but I know how to do both. I'm just not strong in PHP. I also know about the Open Ticket API as I've used it for various WHMCS Hooks 🙂 I've managed to achieve what I want by doing this: <?php use WHMCS\ClientArea; use WHMCS\Database\Capsule; define('CLIENTAREA', true); require __DIR__ . '/init.php'; $ca = new ClientArea(); $ca->initPage(); $email = $_POST["email"]; $phonenumber = Capsule::table('tblclients') ->where('email', '=', $email)->value('phonenumber'); $clientid = Capsule::table('tblclients') ->where('email', '=', $email)->value('id'); // Check if client has an active Phone Support product (id 92) $hasPhoneSupport = Capsule::table('tblhosting') ->where('userid', '=', $clientid) ->where('packageid', '=', '92') ->where('domainstatus', '=', 'Active') ->count(); // Check if client has an active VPS (either ID 60 or 61) $hasVPS = Capsule::table('tblhosting') ->where('userid', '=', $clientid) ->where('packageid', '61') ->where('domainstatus', '=', 'Active') ->orWhere('userid', '=', $clientid) ->where('packageid', '60') ->where('domainstatus', '=', 'Active') ->count(); if(!$phonenumber){ $errormessage = "No phone number has been set for you account"; } elseif($hasVPS == 0 AND $hasPhoneSupport == 0) { $errormessage = "You have no phone support subscription"; } else { $command = 'OpenTicket'; $postData = array( 'deptid' => '2', 'name' => "Dennis", 'email' => "test@test.com", 'subject' => "Phone Support Request", 'message' => $phonenumber, 'priority' => 'Medium', 'useMarkdown' => 'true', ); $adminUsername = 'Admin'; $results = localAPI($command, $postData, $adminUsername); $successMessage = "A supporter will contact to you soon"; } $ca->setTemplate('contactphone'); $ca->output(); And then a simple template file with the following: {if $errormessage} {include file="$template/includes/alert.tpl" type="error" errorshtml=$errormessage} {/if} <div class="container"> <div class="row"> <form action="contactphone.php" method="post" enctype="multipart/form-data" role="form"> <input type="text" name="email" placeholder="Email" /> <input type="submit" name="submit" /> </form> </div> </div> We don't do phone support, except if the client purchases a specific product (either a product called Phone Support or a VPS). When the client wants to talk to us, they should input his email in a form (not logged in necessarily), and the code should check whether there's a phone number assigned to the user, and if he qualifies for phone support. How would I go about showing the errors or a success message? Edited June 17, 2019 by DennisMidjord 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted June 17, 2019 Author Share Posted June 17, 2019 (edited) Nevermind, managed to fix it 😄 It had to use the following: $ca->assign(errormessage, "No phone number has been set for you account"); Thanks for all your help @brian! Please let me buy you a cup of coffee 😄 Edited June 17, 2019 by DennisMidjord 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 17, 2019 Share Posted June 17, 2019 a couple of things with those capsule queries... 1. you don't need '=' with where statements - nothing wrong with them being there, but if you don't add them, it assumes you are checking for equality anyway. 2. that $hasVPS query could be trimmed to... $hasVPS = Capsule::table('tblhosting') ->where('userid',$clientid) ->whereIn('packageid',['60','61']) ->where('domainstatus','Active') ->count(); 30 minutes ago, DennisMidjord said: How would I go about showing the errors or a success message?  I see you've fixed it. Just now, DennisMidjord said: Please let me buy you a cup of coffee 😄 a cup of tea will do. ☕ 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted June 17, 2019 Author Share Posted June 17, 2019 6 minutes ago, brian! said: a cup of tea will do. ☕ Send me your details (PayPal or something like that), and I'll send a few bucks for the help 🙂 I went with the following code: contactphone.tpl: {if $sent} {include file="$template/includes/alert.tpl" type="success" msg=$LANG.phoneSupportRequest.sent textcenter=true} {/if} {if $errormessage} {include file="$template/includes/alert.tpl" type="error" errorshtml=$errormessage} {/if} <div class="container"> <div class="row"> {if !$sent} <form action="contactphone.php" method="post" enctype="multipart/form-data" role="form"> <input type="hidden" name="action" value="send" /> <div class="form-group"> <label for="inputName" class="col-sm-3 control-label">{$LANG.contactemail}</label> <div class="col-sm-7"> <input type="text" name="email" value="{$name}" class="form-control" id="inputName" /> </div> </div> <div class="form-group"> <div class="text-center"> <button type="submit" class="btn btn-primary">{$LANG.contactsend}</button> </div> </div> </form> {/if} </div> </div> contactphone.php <?php use WHMCS\ClientArea; use WHMCS\Database\Capsule; define('CLIENTAREA', true); require __DIR__ . '/init.php'; $ca = new ClientArea(); $ca->initPage(); $contactFormSent = false; $email = $_POST["email"]; $phonenumber = Capsule::table('tblclients') ->where('email', '=', $email)->value('phonenumber'); $clientid = Capsule::table('tblclients') ->where('email', '=', $email)->value('id'); // Check if client has an active Phone Support product (id 92) $hasPhoneSupport = Capsule::table('tblhosting') ->where('userid', '=', $clientid) ->where('packageid', '=', '92') ->where('domainstatus', '=', 'Active') ->count(); // Check if client has an active VPS (either ID 60 or 61) $hasVPS = Capsule::table('tblhosting') ->where('userid', '=', $clientid) ->where('packageid', '61') ->where('domainstatus', '=', 'Active') ->orWhere('userid', '=', $clientid) ->where('packageid', '60') ->where('domainstatus', '=', 'Active') ->count(); if( $action == "send" ) { if(!$phonenumber){ $ca->assign(errormessage, "No phone number has been set for you account"); } elseif($hasVPS == 0 AND $hasPhoneSupport == 0) { $ca->assign(errormessage, "You have no phone support subscription"); } else { $command = 'OpenTicket'; $postData = array( 'deptid' => '2', 'name' => "Replace with client's username", 'email' => "Replace with client's email", 'subject' => "Phone Support Request", 'message' => $phonenumber, 'priority' => 'Medium', 'useMarkdown' => 'true', ); $adminUsername = 'Admin'; $results = localAPI($command, $postData, $adminUsername); $ca->assign("sent", true); } } $ca->setTemplate('contactphone'); $ca->output(); If a client has no valid subscription: If the message was sent successfully: 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted June 17, 2019 Author Share Posted June 17, 2019 Thanks again, @brian! 16 minutes ago, brian! said: 2. that $hasVPS query could be trimmed to...  $hasVPS = Capsule::table('tblhosting') ->where('userid',$clientid) ->whereIn('packageid',['60','61']) ->where('domainstatus','Active') ->count(); Great. I read about 'whereIn', but I did '->whereIn('packageid', ('60, 61')' instead and couldn't get it working. I'll update my code to match yours 🙂 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.