Load image from web page, captcha, fill textfield - iphone

Good evening. In my application I need to send a request to a web page that needs a captcha. The image link is a .php and the captcha change every time I refresh the page. So, if I try to download the image "by link", I have a different captcha. What is the solution? Any idea? Thank you in advance.
EDIT: Now I have to fill the input and send the request to submit. This is the html source of textfields I have to fill:
<label class="ins" for="targ">Targa del veicolo:</label>
<input id="targ" name="targa" value="" type="text" size="20" maxlength="8" tabindex="2" />
<label for="inCaptchaChars">Codice di sicurezza:</label> <input type="text" id="inCaptchaChars" name="inCaptchaChars" tabindex="1004" onblur="ShutMeDown()">
And this is about the submit button:
<input type="submit" name="procedi" value="Calcola importo" />
What I have to do to proceed? I have to use ASIHTTP?

This might be a little convoluted, but it should work alright:
Use a webView, load the page, when the page loaded call some javascript on the webview (stringByEvaluatingJavascript) that gets the image size and offset. Resize the WebView frame to that size, and scroll the content to that offset. Disable user interaction and show the webview.
To get the element offset you can use this answer
Simply call:
[[webView stringByEvaluatingJavascript:#"function getOffset(el) { ..... } getOffset( document.getElementById('yourElId') ).left;"] floatValue];
not that you must pass the whole code to this method
To submit the captcha:
As before, call
[webView stringByEvaluatingJavascript :#"document.getElementsByName('procedi')[0].value = 'your captcha';"];
then do the same to call .click() on the submit button or .submit() on the form

Related

Form action forwards me to another page showing JSON (JavaScript)

I have a simple (mostly-working) submission form:
<form action="http://127.0.0.1:3000/books" method="POST" class="addBook">
<input type="text" placeholder="Title" name="title" required>
<input type="text" placeholder="ISBN" name="isbn" required>
<button id="submitBook" type="submit" onclick="addingBooks()">Submit</button>
</form>
My form properly adds the input values to my database and it then appears in the DOM when I go back and refresh the page.
I have applied an preventDefault() function in my JavaScript code for the 'addingBooks()' function to stop it from submitting twice, but I am still unable to stop it from forwarding to the action page after submission which only shows the JSON of the submitted data.
If you need more then please let me know.
To prevent the default action of an event you'll need an event object to call preventDefault on. Some browser do in fact have a global event object but that might not be reliable.
The simplest option would be to return false from the onlick event, not from a function you call in it
<button id="submitBook" type="submit" onclick="addingBooks();return false;">Submit</button>
another simple and better solution would be to make the button be a regular button instead of a submit button and remove the preventDefault from addingBooks.
<button id="submitBook" type="button" onclick="addingBooks()">Submit</button>
another and even better solution would be to not use the onclick attribute at all, use the addEventListener function
document.getElementById('submitBook').addEventListener("click", function(e){
e.preventDefault();
//other stuff
});

webview control: how do post data from the app to a field on the webpage?

i would like to have full control over the webview control. for instance, i would like to know if it is navigating or if it has completed navigating to the desired page. I would then wish to push same data from the app like the user name and password to a field on the page that was opened by the webview.
Could you point me to some examples or tutorials please?
Thank you!
Rely on the following post for javascript injection:
Inject javascript into WebChromeClient
Now just change the underlying javascript. It is important to understand that the Javascript directly is affected by the HTML, so if the HTML is changed, the Javascript (and probably also your app, require an update).
So in case you got the following HTML:
<form action="#" autocomplete="on">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<button type="submit">Login</button>
</form>
The javascript would look like the following, to
set the username
set the password
autologin by clicking login button
$('input[name=\"username\"]').val('%#'); // 1.
$('input[name=\"password\"]').val('%#'); // 2.
$('.login').click(); // 3.
Now just load this by the webview:
public void onPageFinished(WebView view, String url)
{
String loadPasswordJS = "$('input[name=\"username\"]').val('%#'); $('input[name=\"password\"]').val('%#'); $('.login').click();";
view.loadUrl(loadPasswordJS);
}

Passing value outside form

I need to get the value from outside the form. My gsp looks like this
<g:textField name="email" value="${someInstance?.email}"/>
<input type="button" id="checkEmail" class="button" value="Validate" onclick="checkEmail()"/>
<span id="responseDiv"></span>
<g:form action="save">
someCode
<g:submitButton disabled="true" style="color:#999999;" class="save" name="save" action="save" id="saveButton" value="${message(code: 'default.button.save.label', default: 'Submit')}"/>
</g:form>
First, to check if an email is in use, click button (id="checkEmail") and onclick goes to js code checkEmail() which has remoteFunction that updates responseDiv. After that, user enters information to the form, and user clicks submitButton. When that submit button is clicked, I would like my gsp to send email value along with other information to the controller. Any suggestion?
Thanks in advance.
Easy, put the input inside the form.
If that isn't an option for some reason, use the callback to update a hidden field inside the form with something like $("#hiddenEmail").val(emailAddress);
PS. I like how you gave a span an id of responseDiv :)

Dont hide keyboard after pressing Submit in jQueryMobile / Mobile Safari

I am working on a mobile web based form for iOS/Android browsers. Everything works fine functionally.
What I can't seem to do is keep the keyboard on top AFTER the User presses the 'Submit' button on the form. Currently, as soon as I tap 'Submit' the keyboard hides by default. I have tried whatever I could think of before posting this request here.
My code:
<form action="" onsubmit="return false;">
<input id='chat' type="text" name="message" value="" data-inline="true" placeholder="Start typing your message here" />
<button id='doSend' type="submit" data-inline="true">Submit</button>
</form>
Am testing this with jQueryMobile 1.0 beta2 + iPhone 4.
Any ideas are appreciated. Thank you.
Try adding focus back to the '#chat' field on a callback / after your submit has completed.
$('#chat').focus();
Here is a demo I created that simulates the functionality (tested on iPhone)...
Demo: http://jsfiddle.net/wdm954/hYn7k/1/

How do I keep track of when what is the text entered in the form when the user navigates away from the page?

I have a piece of code like this.
<form method="get" action="{$self}" name="addcommentform">
<textarea title="{$enterComment}" name="comment" class="commentarea" </textarea>
<input class="Button" type="submit" value="{$postComment}" />
</form>
How do I keep track of when what is the text entered in the form's textarea when the user navigates away from the page? I want to prompt the user with a warning message so he/she doesn't lose the text.
Thanks.
You could use the javascript/jquery blur event, and if the user hasn't clicked the desired button have it display the form values. This might help JQuery Blur Validation Problem
Stu
Take a look at this Javascript code snippet:
http://www.boutell.com/newfaq/creating/disableclose.html
This takes advantage of the window's onbeforeunload event which fires when the user is about to leave the page.