I'm building a Mac OS native application that uses a WebView to display custom data forms. The user will be able to fill out these forms to input data to the application. I need to be able to capture whatever data gets submitted as part of these html forms.
So if for example a webform comes up that has a text field which the user can use to enter a name - along with an 'OK' button next to it which submits the data - I would need to be able to capture whatever the user entered in that text field.
Keep in mind the HTML is loaded locally, not from a URL. Like so:
[[webview mainFrame] loadHTMLString:htmlSource baseURL:nil];
How can I capture any data that is being send entered this way?
This can easily be done in javascript, by intercepting the submit of your form and tracking the data. For this answer, I assume your webpage uses jQuery:
[webView stringByEvaluatingJavaScriptFromString:#" \
$('#yourForm').on('submit', function(e){ \
console.log(JSON.stringify($(this).serializeArray()));\
});"];
If you need this information in the Objective-C code, this thread describes how to bridge calls between javascript and Obj-C
Related
I have a form that allows the user to upload several images to a server. This form also allows the user to edit the form as well depending upon qs parameters. As additional information, I am using redux-saga with react, just to provide more background.
I am able to upload the image and allow the user to preview the image after they make their selection and before they upload it. However, upon reviewing the documentation, I do not see a way to populate the react-dropzone field when the user edits the other form items. I saw a way to do a preview onDrop but not with data coming from the server. I also found this article on Stackoverflow because am not sure if it could be applied to my case within the redux-saga scenario: How to add the URL of an image already uploaded, to Dropzone?.
Can this be done and if so how can it be achieved?
I'm trying to simulate the entry of a string in a textbox on a web form, submit that form, and then receive the result back from the server. The idea is to allow the user to input the relevant form field in a native iOS control, and then grab the data they're after for them (it requires a few intermediate steps).
The site in question is this: https://www.sinet.uq.edu.au/psp/ps/EMPLOYEE/HRMS/c/UQMY_GUEST.UQMY_GUEST_TTBLE.GBL
I want to provide values for the 'select semester' dropdown (id="UQ_DRV_TT_GUEST_STRM"), and for the 'course code' textbox (id="UQ_DRV_CRSE_SRC_UQ_SUBJECT_SRCH").
To submit, I want to simulate hitting the 'Search' button at the bottom of the page (id="UQ_DRV_TT_GUEST_UQ_SEARCH_PB", onclick="hAction_win0(document.win0,'UQ_DRV_TT_GUEST_UQ_SEARCH_PB', 0, 0, 'Search', false, true);").
I've looked into using an ASIFormDataRequest object from the ASIHTTPRequest library to send through POST values, but either I'm getting the key/value pairs wrong or I'm approaching this in the wrong way.
If someone could point me in the right direction that'd be great. In particular, should I be somehow running the hAction_win0(...) call, and if so, how would I set the appropriate values? If this isn't necessary, what should the POST values be?
Thanks :)
you can use a JavaScript to set the values, use following code to evaluate it in browser:
[myWebView stringByEvaluatingJavaScriptFromString:JSstring];
Create a NSString with the fields separated by a "&". For example, say I have two fields: name and email. Then it should be:
#"name='John Balls'&email='john#mac.com'";
Create a NSData object from that string by using -dataUsingEncoding:NSUTF8StringEncoding and send it as the HTTP body.
I need to POST a HTML form to a 3rd party website (a Mass-SMS texting system).
In the past I've done this by forwarding to a page containing a form I've pre-populated and hidden (using display:none), then I've ran a javascript function at the end of the page to automatically submit this form.
However I'm hoping theres someway I can do all this programmatically (as I don't care about the response, and the user doesn't need to see the page the form is being posted to).
How can I do this? Cheers
You could use a WebClient.UploadValues method to send an HTTP POST request to a remote server from your code behind. Just fill up the name/value collection with the values coming from the hidden fields.
If you're willing to get into PHP, you can very easily use cURL for this.
Otherwise it's going to be quite difficult using just Javascript.
See here for a detailed tutorial.
I had a quick question regarding UIWebView. Is there anyway to programmatically navigate the UIWebView? Essentially, I prompt the user for certain information, such as (Current Location, Time). Using this information, I would like to fill out and complete a form on a webpage, and display the resulting UIWebView to the user. Is this possible?
You could use JavaScript to control the UIWebView using the stringByEvaluatingJavaScriptFromString method. For example you should be able to insert text into an input and submit a form:
NSString* script = #"document.getElementById('Name').value = 'Hello'; document.getElementsByTagName('form')[0].submit();";
[self.web stringByEvaluatingJavaScriptFromString:script];
You'd have to customize the JavaScript to do whatever you want. For example, you could inject values that you had collected into the script, then run the JavaScript.
You could hide the UIWebView until the new page had loaded, then show it to the user.
Come to think of it, it'd be nice if there were a Selenium type wrapper around the web view, but I don't know of anything like that right now.
Is it possible to make a program that open a page (as if a bookmark file were opened by IE), and based on its content generate a feedback, that should be fedback in a textbox on said page by pressing a button on said page?
I need this program to execute on a set time schedule to feed some data to a web server based on time dependent web page data.
Yes, that is possible. It is generally called screen scraping. You basically retrieve the web page in question via a HTTP request, parse/analyze the page you got, then send back the data that should go into the textbox (again a HTTP request).
There are libraries to do that. Here is an article describing an example in Perl:
http://www.perl.com/pub/a/2003/01/22/mechanize.html