Reputation: 3600
I am wondering if there is a way to create a form in a native iOS app and submit it via Google Forms. Here is an example on a web page of what I'm wanting to do natively in an iOS app.
http://onmyhonorband.com/streetteam
Upvotes: 1
Views: 2345
Reputation: 295
I started working with Joe's response above (https://stackoverflow.com/a/23451577/879231) but was getting a 404 on the request without adding an /e
after the /d
that was in the his URL. Found this by comparing the share form link with what Joe had. Little testing and got it working. Below is my code using Swift and AlamoFire just cause I already had it in my project. Note: The contactInfo.paramaters
I'm passing in is a just a simple struct with a computed parameters
property to spit out the collected info from my iOS version of the form.
func upload() {
var headers = HTTPHeaders()
headers["Content-Type"] = "application/x-www-form-urlencoded"
Alamofire.request("https://docs.google.com/forms/d/e/<enter your forms ID here>/formResponse",
method: .post,
parameters: contactInfo.paramaters,
headers: headers).validate().response { (response) in
print(response)
}
}
Upvotes: 0
Reputation: 39181
Yes there is a way, I used this method in this repo: https://github.com/goktugyil/QorumLogs
Here is the tutorial of how to set it up: https://github.com/goktugyil/QorumLogs/blob/master/Log%20To%20GoogleDocs.md
Heres the code to do it:
private static var googleFormLink: String!
private static var googleFormAppVersionField: String!
private static var googleFormUserInfoField: String!
private static var googleFormMethodInfoField: String!
private static var googleFormErrorTextField: String!
/// Setup Google Form links
static func setupOnlineLogs(#formLink: String, versionField: String, userInfoField: String, methodInfoField: String, textField: String) {
googleFormLink = formLink
googleFormAppVersionField = versionField
googleFormUserInfoField = userInfoField
googleFormMethodInfoField = methodInfoField
googleFormErrorTextField = textField
}
private static func sendError(#text: String) {
var url = NSURL(string: googleFormLink)
var postData = googleFormAppVersionField + "=" + text
postData += "&" + googleFormUserInfoField + "=" + "anothertext"
postData += "&" + googleFormMethodInfoField + "=" + "anothertext"
postData += "&" + googleFormErrorTextField + "=" + "anothertext"
var request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding)
var connection = NSURLConnection(request: request, delegate: nil, startImmediately: true)
}
Upvotes: 0
Reputation: 3761
You can see how to create a URL Request with post variables over at this post:
Append data to a POST NSURLRequest
You can find the URL and variable names by inspecting your current form's HTML. In your case post to the URL:
https://docs.google.com/forms/d/1vlYPlNi4xJv6JCHpLrHD6oSrYgUqWOrzF8z6KJjTVuE/formResponse
Paramaters will be entry.1615511943
, entry.1186557728
, etc. You'll also find these in the HTML input's 'name'.
Set the doc type like this:
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
The data itself is just strings, you'll have to build a UI and pull them from there.
Upvotes: 4
Reputation: 29
You can do it as follow:
Upvotes: -1