Google スプレッドシートには、データをスプレッドシートに投稿できるフォームを作成する機能があります。これは、Google API 経由では行われません。
次のコードを使用して、データをフォームに投稿しています。
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$googleformURL);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$data = curl_exec ($ch);
curl_close($ch);
//echo $data;
//Redirect to your thank you page
header( "Location: $thankyou" ) ;
?>
これは問題なく動作しますが、Google スプレッドシートでデータを見ると、ÅÄÖ などのすべての特殊文字が欠落しています。これはエンコードエラーだと思います。これが機能するようにコードを変更するにはどうすればよいですか? 以下は、元のフォームのサンプルです。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk2.png" type="image/x-icon">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Untitled form</title>
<link href='/static/spreadsheets/client/css/779923916-published_form_compiled.css' type='text/css' rel='stylesheet'>
</head>
<body class="ss-base-body" dir="ltr" itemscope itemtype="http://schema.org/CreativeWork/FormObject"><meta itemprop="name" content="Untitled form">
<meta itemprop="embedUrl" content="https://docs.google.com/spreadsheet/embeddedform?formkey=dGJ3ZTdNQ0xwQUJKeGp0dVpDbElVTHc6MQ">
<meta itemprop="faviconUrl" content="//ssl.gstatic.com/docs/spreadsheets/forms/favicon_jfk2.png">
<div class="ss-form-container">
<div class="ss-form-heading"><h1 class="ss-form-title">Untitled form</h1>
<p></p>
<hr class="ss-email-break" style="display:none;">
</div>
<div class="ss-form"><form action="https://docs.google.com/spreadsheet/formResponse?formkey=dGJ3ZTdNQ0xwQUJKeGp0dVpDbElVTHc6MQ&ifq" method="POST" id="ss-form">
<br>
<div class="errorbox-good">
<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_0">Namn
</label>
<label class="ss-q-help" for="entry_0"></label>
<input type="text" name="entry.0.single" value="" class="ss-q-short" id="entry_0"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_1">Gatuadress
</label>
<label class="ss-q-help" for="entry_1"></label>
<input type="text" name="entry.1.single" value="" class="ss-q-short" id="entry_1"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_2">Postnummer
</label>
<label class="ss-q-help" for="entry_2"></label>
<input type="text" name="entry.2.single" value="" class="ss-q-short" id="entry_2"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_3">Ort
</label>
<label class="ss-q-help" for="entry_3"></label>
<input type="text" name="entry.3.single" value="" class="ss-q-short" id="entry_3"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_4">E-post
</label>
<label class="ss-q-help" for="entry_4"></label>
<input type="text" name="entry.4.single" value="" class="ss-q-short" id="entry_4"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_5">Sort
</label>
<label class="ss-q-help" for="entry_5"></label>
<input type="text" name="entry.5.single" value="" class="ss-q-short" id="entry_5"></div></div></div>
<br> <div class="errorbox-good">
<div class="ss-item ss-paragraph-text"><div class="ss-form-entry"><label class="ss-q-title" for="entry_7">Story
</label>
<label class="ss-q-help" for="entry_7"></label>
<textarea name="entry.7.single" rows="8" cols="75" class="ss-q-long" id="entry_7"></textarea></div></div></div>
<br>
<input type="hidden" name="pageNumber" value="0">
<input type="hidden" name="backupCache" value="">
<div class="ss-item ss-navigate"><div class="ss-form-entry">
<input type="submit" name="submit" value="Submit"></div></div></form>
<script type="text/javascript">
(function() {
var divs = document.getElementById('ss-form').
getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className == 'errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
for (var i = 0; i < numDivs; i++) {
var div = divs[i];
if (div.className == 'ss-form-entry' &&
div.firstChild &&
div.firstChild.className == 'ss-q-title') {
div.lastChild.focus();
return;
}
}
})();
</script></div>
<div class="ss-footer"><div class="ss-attribution"></div>
<div class="ss-legal"><span class="ss-powered-by">Powered by <a href="http://docs.google.com">Google Docs</a></span>
<span class="ss-terms"><small><a href="https://docs.google.com/spreadsheet/reportabuse?formkey=dGJ3ZTdNQ0xwQUJKeGp0dVpDbElVTHc6MQ&source=https://docs.google.com/spreadsheet/viewform?formkey%3DdGJ3ZTdNQ0xwQUJKeGp0dVpDbElVTHc6MQ">Report Abuse</a>
-
<a href="http://www.google.com/accounts/TOS">Terms of Service</a>
-
<a href="http://www.google.com/google-d-s/terms.html">Additional Terms</a></small></span></div></div></div></body></html>