I have a UIWebView and I have a simple form like this:
<form action="http://message/">Your Email: <input id="email" /><br />
<input type="submit" value="Submit" />
</form>
and right now there is no JS validation, and the form just gets submitted somewhere and I am not sure how to get the field values. All I have in my controller is this:
- (BOOL)webView:(UIWebView *)aWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.scheme isEqualToString:@"message"])
{
// RIGHT NOW THIS DOESNT WORK...HOW DO I GET IT RIGHT? :)
NSString *useremail = [theWebView stringByEvaluatingJavaScriptFromString:@"getEmail()"];
NSLog(useremail);
}
return YES;
}
I am not sure how exactly to get the controller to see what the field values and how to validate the field values in the js.
Please advise me how to best accomplish this.
I also tried creating a JavaScript function to simply hit the request url (that is all I really need) but that is not sending the request url:
<script type="text/javascript">
function test ()
{
// Het the params.
var name = escape(document.getElementById("name").value);
var email = escape(document.getElementById("email").value);
var phone = escape(document.getElementById("phone").value);
var url="http://www.myurl.com?platform=ios&name="+name+"&email="+email+"&phone="+phone;
alert(url);
var ajaxObj = createXMLHttp();
//var url = 'myrequest.php';
ajaxObj.open("GET", url, true);
ajaxObj.onreadystatechange = function()
{
ajaxObj.processRequest();
}
ajaxObj.send(null);
ajaxObj.processRequest = function()
{
if (this.readyState == 4)
{
// got response
}
}
alert("1");
var req ;
// Browser compatibility check
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
var req = new XMLHttpRequest();
req.open("GET", url ,true);
req.onreadystatechange = function ()
{
//document.getElementById('divTxt').innerHTML = "Contents : " + req.responseText;
}
req.send(null);
return false;
}
</script>
Thanks!
How about something like this: