In this example demo we will create a simple php form and send the data to Netsuite to create a contact record through PHP Toolkit for SuiteTalk WebServices.
First you need to download the php tool kit and define configuration like connection details in php config file.
After that you need to import
require_once ‘../PHPToolkit/NetSuiteService.php’;
In each php file where you want to use the Netsuite Webservices for PHP
<!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php require_once '../PHPToolkit/NetSuiteService.php'; if ($_SERVER["REQUEST_METHOD"] == "POST") { $contact = new Contact(); $contact->entityId =$_POST["firstName"]. ' ' .$_POST["lastName"]; $contact->firstName = $_POST["firstName"]; $contact->lastName = $_POST["lastName"]; $contact->phone = $_POST["phone"]; $contact->email = $_POST["email"]; $contact->comments = $_POST["comments"]; $subsidiary = new Subsidiary(); $subsidiary->internalId = 12; // India Subsidiary internal id $contact->subsidiary = $subsidiary; $request = new AddRequest(); $request->record = $contact; $service = new NetSuiteService(); $addResponse =$service->add($request); if (!$addResponse->writeResponse->status->isSuccess) { echo "ADD ERROR"; } else { echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId; } } ?> <h2>PHP SOAP CALL TO NETSUITE To ADD CONTACT</h2> <form method="post" action="<?php $_SERVER["PHP_SELF"] ?>"> First Name: <input type="text" name="firstName"><br><br> Last Name: <input type="text" name="lastName"><br><br> E-mail: <input type="text" name="email"><br><br> Phone: <input type="text" name="phone"><br><br> Comments: <textarea name="comments" rows="5" cols="40"></textarea> <br><br> <input type="submit" name="submit" value="Submit"> </form> <?php ?> </body> </html>
When you will run the above code. You will get a form like this
Fill the form and click submit. You should get Add Success message with ID
That’s all
Leave a Reply