Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <?php
  2. $errors = array(); // use this to create an associative array to json encode and send back any errors
  3. $rowData = array(); // this will be the associative array that gets passed to the insertRow method
  4.  
  5. $firstName = $_POST['firstName'];
  6.  
  7. if(isset($firstName)){
  8. $rowData['firstname'] = $firstName; // note the key 'firstname' must equal the column header in your spreadsheet which you are inserting the value into. the column header name key should be all lowercase and not contain spaces regardless of if you have it in the spreadsheet
  9. }else{
  10. $errors['firstname'] = '1';
  11. }
  12.  
  13. $lastName = $_POST['lastName'];
  14.  
  15. if(isset($lastName)){
  16. $rowData['lastname'] = $lastName; // note the key 'lastname' must equal the column header in your spreadsheet which you are inserting the value into. the column header name key should be all lowercase and not contain spaces regardless of if you have it in the spreadsheet
  17. }else{
  18. $errors['lastname'] = '1';
  19. }
  20.  
  21.  
  22. set_include_path($_SERVER['DOCUMENT_ROOT'] . '/library/');
  23.  
  24. $spreadsheetKey = 'your-spreadsheet-key';
  25. $worksheetId = 'your-worksheet-id'; // if you only have one worksheet this will be 'od6'
  26.  
  27. require_once 'Zend/Loader/Autoloader.php';
  28. $autoloader = Zend_Loader_Autoloader::getInstance();
  29. $autoloader->setFallbackAutoloader(true);
  30.  
  31. $user = "your-user-name-at-gmail-dot-com";
  32. $pass = "your-password";
  33.  
  34. $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
  35. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  36. $spreadsheetService = new Zend_Gdata_Spreadsheets($client);
  37.  
  38. $query = new Zend_Gdata_Spreadsheets_DocumentQuery();
  39. $query->setSpreadsheetKey($spreadsheetKey);
  40. $feed = $spreadsheetService->getWorksheetFeed($query);
  41.  
  42. global $spreadsheetService,$spreadsheetKey,$worksheetId,$rowData;
  43. $insertedListEntry=$spreadsheetService->insertRow($rowData,$spreadsheetKey,$worksheetId);
  44. $returnObject['success'] = 'true';
  45. echo(json_encode($returnObject));
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement