deBackupProvider Posted July 7, 2009 Share Posted July 7, 2009 Hello, For a remote order form I need to retrieve the orderid from the database to get the order accepted by the available api code. I use the script matt posted here on the forum http://forum.whmcs.com/showthread.php?t=12169&highlight=remote+order+form My question: How can I retrieve the order ID in my form to get the accept order api working: $postfields["action"] = "acceptorder"; $postfields["orderid"] = "ORDERID"; Thanks in advance. 0 Quote Link to comment Share on other sites More sharing options...
Lawrence Posted July 8, 2009 Share Posted July 8, 2009 If you post the code, someone may be able to point out what you are doing wrong 0 Quote Link to comment Share on other sites More sharing options...
deBackupProvider Posted July 8, 2009 Author Share Posted July 8, 2009 Oops, here it is The bold part is where I want to retrieve the orderd id. <?php $whmcsurl = "WHMCS URL"; $apiusername = "USERNAMEr"; # Admin username goes here $apipassword = "PASSWORD"; # Admin password goes here if ($_POST["action"]=="submit") { # Get Values $pid = trim(htmlentities($_POST["pid"])); $firstname = trim(htmlentities($_POST["firstname"])); $lastname = trim(htmlentities($_POST["lastname"])); $companyname = trim(htmlentities($_POST["companyname"])); $email = trim(htmlentities($_POST["email"])); $address1 = trim(htmlentities($_POST["address1"])); $address2 = trim(htmlentities($_POST["address2"])); $city = trim(htmlentities($_POST["city"])); $state = trim(htmlentities($_POST["state"])); $postcode = trim(htmlentities($_POST["postcode"])); $country = trim(htmlentities($_POST["country"])); $phonenumber = trim(htmlentities($_POST["phonenumber"])); $password = trim(htmlentities($_POST["password"])); $password2 = trim(htmlentities($_POST["password2"])); $tosagreement = $_POST["tosagreement"]; # Error Checking if (!$firstname) { $errors[] = "You did not enter your first name"; } if (!$lastname) { $errors[] = "You did not enter your last name"; } if (!$email) { $errors[] = "You did not enter your email address"; } elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$", $email)) { $errors[] = "The email address you entered is invalid"; } if (!$address1) { $errors[] = "You did not enter the first line of your address"; } if (!$city) { $errors[] = "You did not enter your city"; } if (!$state) { $errors[] = "You did not enter your state"; } if (!$postcode) { $errors[] = "You did not enter your postcode"; } if (!$country) { $errors[] = "You did not enter your country"; } if (!$phonenumber) { $errors[] = "You did not enter your phone number"; } if (!$password) { $errors[] = "You must enter a password"; } elseif ($password!=$password2) { $errors[] = "The password you entered did not match"; } if (!$tosagreement) { $errors[] = "You must agree to the terms of service"; } if (!$errors) { # Submit Order $apiurl = $whmcsurl."includes/api.php"; # URL to WHMCS API file $postfields = array(); $postfields["username"] = $apiusername; $postfields["password"] = md5($apipassword); $postfields["action"] = "addclient"; $postfields["firstname"] = $firstname; $postfields["lastname"] = $lastname; $postfields["companyname"] = $companyname; $postfields["email"] = $email; $postfields["address1"] = $address1; $postfields["address2"] = $address2; $postfields["city"] = $city; $postfields["state"] = $state; $postfields["postcode"] = $postcode; $postfields["country"] = $country; $postfields["phonenumber"] = $phonenumber; $postfields["password2"] = $password; $query_string = ""; foreach ($postfields AS $k=>$v) { $query_string .= "$k=".urlencode($v)."&"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiurl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); $data = curl_exec($ch); curl_close($ch); $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } if ($results["result"]=="success") { $clientid = $results["clientid"]; } else { die("An error occured. Please contact support. ({$results['message']})"); } $postfields = array(); $postfields["username"] = $apiusername; $postfields["password"] = md5($apipassword); $postfields["action"] = "addorder"; $postfields["clientid"] = $clientid; $postfields["pid"] = $pid; $postfields["paymentmethod"] = "mailin"; $postfields["noemail"] = "true"; $query_string = ""; foreach ($postfields AS $k=>$v) { $query_string .= "$k=".urlencode($v)."&"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiurl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); $data = curl_exec($ch); curl_close($ch); $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } if ($results["result"]=="success") { $orderid = $vars["OrderID"]; } else { die("An error occured. Please contact support. ({$results['message']})"); } $postfields = array(); $postfields["username"] = $apiusername; $postfields["password"] = md5($apipassword); $postfields["action"] = "acceptorder"; $postfields["orderid"] = $orderid; $query_string = ""; foreach ($postfields AS $k=>$v) { $query_string .= "$k=".urlencode($v)."&"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiurl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); $data = curl_exec($ch); curl_close($ch); $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } if ($results["result"]=="success") { $invoiceid = $results["invoiceid"]; header("Location: ".$whmcsurl."cart.php?a=complete"); exit; } else { die("An error occured. Please contact support. ({$results['message']})"); } } } ?><html> <head> <title>Order Form</title> </head> <body> <h1>Order Form</h1> <?php if ($errors) { echo "<p>The following errors occured.</p><ul>"; foreach ($errors AS $error) { echo "<li>$error</li>"; } echo "</ul>"; } ?> <form method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>"> <input type="hidden" name="action" value="submit" /> <table> <tr><td><b>Hosting Details</b></td></tr> <tr><td>Hosting Package</td><td> <input type="radio" name="pid" value="23"<?php if (($pid=="23")OR(!$pid)) { echo " checked"; } ?> /> Starter Package </td></tr> <tr><td><br /></td></tr> <tr><td><b>Your Details</b></td></tr> <tr><td>First Name</td><td><input type="text" name="firstname" size="30" value="<?php echo $firstname ?>" /></td></tr> <tr><td>Last Name</td><td><input type="text" name="lastname" size="30" value="<?php echo $lastname ?>" /></td></tr> <tr><td>Company Name</td><td><input type="text" name="companyname" value="<?php echo $companyname ?>" size="30" /></td></tr> <tr><td>Email Address</td><td><input type="text" name="email" value="<?php echo $email ?>" size="30" /></td></tr> <tr><td>Address 1</td><td><input type="text" name="address1" value="<?php echo $address1 ?>" size="30" /></td></tr> <tr><td>Address 2</td><td><input type="text" name="address2" value="<?php echo $address2 ?>" size="30" /></td></tr> <tr><td>City</td><td><input type="text" name="city" size="30" value="<?php echo $city ?>" /></td></tr> <tr><td>State</td><td><input type="text" name="state" size="30" value="<?php echo $state ?>" /></td></tr> <tr><td>Postcode</td><td><input type="text" name="postcode" size="30" value="<?php echo $postcode ?>" /></td></tr> <tr><td>Country</td><td><input type="text" name="country" size="30" value="<?php echo $country ?>" /></td></tr> <tr><td>Phone Number</td><td><input type="text" name="phonenumber" size="30" value="<?php echo $phonenumber ?>" /></td></tr> <tr><td>Password</td><td><input type="password" name="password" size="30" /></td></tr> <tr><td>Confirm Password</td><td><input type="password" name="password2" size="30" /></td></tr> </table> <p align="center"><input type="checkbox" name="tosagreement" /> I have read and agree to the <a href="http://www.yourdomain.com/terms.html" target="_blank">Terms of Service</a></p> <p align="center"><input type="submit" value="Submit Order" /></p> </form> </body> </html> 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.