{"id":342,"date":"2013-07-30T17:59:47","date_gmt":"2013-07-30T07:59:47","guid":{"rendered":"http:\/\/tupps.com\/?p=342"},"modified":"2013-07-30T17:25:33","modified_gmt":"2013-07-30T07:25:33","slug":"submitting-information-to-jotform-from-an-ios-app","status":"publish","type":"post","link":"https:\/\/tupps.com\/?p=342","title":{"rendered":"Submitting information to JotForm from an iOS App"},"content":{"rendered":"<p>This basic example will show you how to get submit data to a <a href=\"http:\/\/www.jotform.com\">JotForm<\/a> form from an iOS app. JotForm makes it extremely quick easy to setup a form, and it provides all the backend support you need to manage that data. If you have a need to submit some data from an iOS app back to you it is ideal, especially if you can stay under the 100 submissions a month limit for a free account. I am looking at all the &#8216;contact us&#8217; and submit a question screens out there. <\/p>\n<p>To get started you will need to create a form using JotForm&#8217;s web builder. One great bit of UX is the fact you can do this without signing up for an account.<\/p>\n<p>I have setup a simple contact form, with first name, last name and a comments field. <\/p>\n<p><a href=\"http:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-13-14.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-13-14-300x192.png\" alt=\"2013-07-30_07-13-14\" width=\"300\" height=\"192\" class=\"aligncenter size-medium wp-image-343\" srcset=\"https:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-13-14-300x192.png 300w, https:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-13-14.png 913w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <\/p>\n<p>To see the form details you will need to load a sample of the form. You do this by going to the &#8216;My Forms&#8217; button at the top of the page, selecting your form and choosing the View Form from the more button on the resulting page. <\/p>\n<p><a href=\"http:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-17-422.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-17-422-300x131.png\" alt=\"2013-07-30_07-17-42\" width=\"300\" height=\"131\" class=\"aligncenter size-medium wp-image-346\" srcset=\"https:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-17-422-300x131.png 300w, https:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-17-422.png 887w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>There will be a couple of bits of key information that you need to gather from your sample form. The first is the formID, you will see that as a 14 digit number in the URL. Then you will need to get the field ids. Do this by opening up the source and looking name fields on the inputs. <\/p>\n<p><a href=\"http:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-25-36.png\"><img decoding=\"async\" src=\"http:\/\/tupps.com\/wp-content\/uploads\/2013\/07\/2013-07-30_07-25-36.png\" alt=\"2013-07-30_07-25-36\" class=\"aligncenter size-medium wp-image-347\" \/><\/a><\/p>\n<p>With these details we are able to construct a request to send to JotForm from an iOS app. I will leave the form creation up to you, but if you need a hand with form creation have a look at the <a href=\"https:\/\/github.com\/chrismiles\/EZForm\">EZ Form ios library<\/a>. To make the submission easier I am using <a href=\"https:\/\/github.com\/AFNetworking\/AFNetworking\">AFNetworking Library<\/a>. <\/p>\n<p><code><br \/>\n    NSURL *url = [NSURL URLWithString:@\"http:\/\/submit.jotform.co\"];<br \/>\n    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];<\/p>\n<p>    NSDictionary *modelData = [self.emailForm modelValues];<br \/>\n    NSDictionary *params = @{@\"q1_firstName\": self.firstName.text,<br \/>\n                             @\"q4_lastName\": self.lastName.text,<br \/>\n                             @\"q3_yourComments\": self.comments.text,<br \/>\n                             @\"simple_spc\":@\"32096649753869-32096649753869\",<br \/>\n                             @\"formID\":@\"32096649753869\"};<\/p>\n<p>    [httpClient postPath:@\"\/submit\/32096649753869\/\" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {<br \/>\n        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];<br \/>\n        NSLog(@\"Request Successful, response '%@'\", responseStr);<br \/>\n    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {<br \/>\n        NSLog(@\"[HTTPClient Error]: %@\", error.localizedDescription);<br \/>\n    }];<br \/>\n<\/code><\/p>\n<p>There are a number of spots where the formID gets copied, both in the URLs and in a number of fields. I included the simple_spc field with the formID repeated to mimic the JotForm javascript API. Then with AFNetworking I submit the request and simply log the success and failure blocks. <\/p>\n<p>The only time that the JotForm api differs is when you submit a file with your form submission. In this case the form changes from simple parameters to a multi-part encoded submission. In that case  you will need to create NSMutableURLRequest:<\/p>\n<p><code>    NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@\"POST\" path:@\"\/submit\/32096649753869\/\" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {<br \/>\n        [formData appendPartWithFileData:UIImageJPEGRepresentation(picture) name:@\"q5_photo\" fileName:@\"photo.jpeg\" mimeType:@\"image\/jpeg\"];<br \/>\n        [formData appendPartWithFormData:[@\"32096649753869\" dataUsingEncoding:NSUTF8StringEncoding] name:@\"formID\"];<br \/>\n        [formData appendPartWithFormData:[self.firstName.text dataUsingEncoding:NSUTF8StringEncoding] name:@\"q1_firstName\"];<br \/>\n        [formData appendPartWithFormData:[self.lastName.text dataUsingEncoding:NSUTF8StringEncoding] name:@\"q4_lastName\"];<br \/>\n        [formData appendPartWithFormData:[self.comments.text dataUsingEncoding:NSUTF8StringEncoding] name:@\"q3_yourComments\"];<br \/>\n        [formData appendPartWithFormData:[@\"32096649753869-32096649753869\" dataUsingEncoding:NSUTF8StringEncoding] name:@\"simple_spc\"];<br \/>\n    }];<\/code><\/p>\n<p>Then the submission is handled by creating a AFHTTPRequestOperation and setting the success and failure handlers. Once they are set it is then a matter of calling  [httpClient enqueueHTTPRequestOperation:operation]; and the request will be submitted. <\/p>\n<p><code><br \/>\n    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];<\/p>\n<p>    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {<br \/>\n        NSLog(@\"Response: %@\", responseObject);<br \/>\n    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {<br \/>\n        NSLog(@\"Failed with error: %@\", error);<br \/>\n    }];<\/p>\n<p>    [httpClient enqueueHTTPRequestOperation:operation];<br \/>\n<\/code><\/p>\n<p>If you want to keep track of your form submission process you can setup a progress block to inform you as bytes are being written.  <\/p>\n<p><code>    [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {<br \/>\n        NSLog(@\"Sent %lld of %lld bytes\", totalBytesWritten, totalBytesExpectedToWrite);<br \/>\n    }];<br \/>\n    <\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This basic example will show you how to get submit data to a JotForm form from an iOS app. JotForm makes it extremely quick easy to setup a form, and it provides all the backend support you need to manage that data. If you have a need to submit some data from an iOS app [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-random-thoughts"],"_links":{"self":[{"href":"https:\/\/tupps.com\/index.php?rest_route=\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tupps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tupps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tupps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tupps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342"}],"version-history":[{"count":5,"href":"https:\/\/tupps.com\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":352,"href":"https:\/\/tupps.com\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions\/352"}],"wp:attachment":[{"href":"https:\/\/tupps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tupps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tupps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}