i have created android app, in want create form using javascript , html, in form first validate user information , pass php file url. problem not able mentioned. can me it.
here code
html form
<body> <div id="id01"></div> <div class="container"> <div class="main"> <form action="#" method="get" onsubmit="return validationevent()"> <label>name :</label><br/> <input type="text" name="name" id="name" placeholder="name" /><br/> <label>email :</label><br/> <input type="text" name="email" id="email" placeholder="valid email" /> <br/> <label>gender :</label><br/> <input type="radio" name="gender" value="male" id="male" /><label>male</label> <input type="radio" name="gender" value="female" id="female" /><label>female</label><br/><br/> <label>contact no. :</label><br/> <input type="text" name="contact" id="contact" placeholder="contact no." /> <br/> <input type="submit" value="submit" /> </form> </div> </div>
javascript code
function validationevent() { //storing field values in variables var name = document.getelementbyid("name").value; var email = document.getelementbyid("email").value; var contact = document.getelementbyid("contact").value; //regular expression email var emailreg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; //conditions if (name != '' && email != '' && contact != '') { if(email.match(emailreg)){ if( document.getelementbyid("male").checked || document.getelementbyid("female").checked ) { if (contact.length == 10) { if (window.xmlhttprequest){ xmlhttp=new xmlhttprequest(); }else { xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function(data){ document.getelementbyid("id01").style.display = "none"; if (xmlhttp.readystate==4 && xmlhttp.status==200){ document.getelementbyid("id01").style.display = "block"; document.getelementbyid("id01").innerhtml = xmlhttp.responsetext; } } xmlhttp.open('get','http://localhost/donotdel/repeat.php?name=' + name +'&email=' + email +'&contact=' + contact,true); xmlhttp.send(); } else{ alert ("the contact no. must @ least 10 digit long!"); return false; } } else{ alert ("you must select gender.....!"); return false; } } else{ alert ("invalid email address...!!!"); return false; } } else{ alert ("all fields required.....!"); return false; } }
and php file be
<?php $name = $_get['name']; echo $name; ?>
if want execute html , javascript, can use webview cannot natively execute php on android.
you can make remote php server , define api webview can call endpoints or can code in java make form.
Comments
Post a Comment