Autosearch http forms - javascript

I'm building a robot using an AI platform to help people access government information (in the public domain). Is there a way of populating a html form of an external website using the information the user has provided and submitting and retrieving the information using javascript.
E.g. say the search form is on https://www.governmentportal.com/court-location , take the user's information obtained previously, autofilling the form, using a program to press search and returning the results? An example of such a form is:
<table width="100%" cellpadding="0" cellspacing="0">
<tbody><tr>
<td class="FormLabel">Rental postcode</td>
<td align="left">
<input name="txtPostCode" type="text" maxlength="8" id="txtPostCode"class="txt">
</td>
</tr>
<tr>
<td class="FormLabel">Tenant's Surname</td>
<td align="left">
<input name="txtSurname" type="text" maxlength="50" id="txtSurname" class="txt">
</td>
</tr>
<tr>
<td class="FormLabel">Month Deposit Paid</td>
<td align="left">
<select name="ddlDepositDateMonth" id="ddlDepositDateMonth" class="ddl"> <option value="mm">mm</option>
</select><select name="ddlDepositDateYear" id="ddlDepositDateYear" class="ddl">
<option value="yyyy">yyyy</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td align="left">
<a id="lnkSearch" class="SearchButton" href="javascript:__doPostBack('lnkSearch','')">Search ></a>
</td>
</tr>
</tbody></table>
Thank you.

It depends what goal you have and what possibilities those pages give you.
If those websites offer an API, you can easily use jQuery.ajax or axios for data fetching, passing the user input on.
If they don't offer an API you could send POST requests with curl (I think PHP supports that out of the box?) or if those sites need Javascript support you can use something like PhantomJS.
What you can't do is to kind of automatically fill out forms in front of the users eye. This needs to happen on the server side (unless we are not talking about viewing your page in a browser).

Related

How to get an input from HTML page and search google sheet for the matching details and then show it on html fields

Im new to coding and i need below solution to one of my project. i'll try my best to explain. Im using google appscript.
I have a HTML file with an ID agent_email_id, when i change the email id (type in an email id) from this input, i want the rest of the input fields (like, name, emp id, supervisor name) to get updated with the data from google sheet for this specific email.
is this possible ? how should i proceed
Any help would be appreciated.
Note: i do not have any code handy, trying to automate certain audits.
<form id="myForm" onsubmit="handleFormSubmit(this)">
<table class="table table-bordered table-striped table-condensed" style="border-style: solid">
<tr>
<td class="" colspan="6">Mandatory Fields </td>
</tr>
<tr>
<th class="">Agent EMP ID</th>
<td class="text-center"><input name="agent_ID" value="agent_ID" type="hidden" class="">
<span class="">agent_ID</span></td>
<th class="">Agent Name: </th>
<td class="text-center"><span class=""></span><input name="agent_name" type="hidden" value="agent_name" class=""><span class="">agent_name</span></td>
<th class="">Agent Email ID </th>
<td class="text-center"><input name="agent_email_ID" id="a_email_id" type="text" value="" class=""></td>
</tr>
For get any information form google sheet using AppScript you have create a API with google sheet.
than you will able to fetch data with email and any other params.
But I want to tell you thats not easy for anyone without learning javascript.

how to force the user to write correctly in HTML input

I have this HTML code in my JSP
<table>
<tr>
<td width="50%" > type your article :
</td>
<td width="50%">
<input type="text" name="article" size="50"/>
</td>
</tr>
</table>
I have in MYSQL database a table 'article' in which i have a column 'designation' , I want to propose a choice of 'designation' to the user according to what is being written.
note: i can not use a dropdownlist because i have more than 1000 designations
Thanks in Advance.
I think you can solve the problem using JQuery Lookup.

Select Image and pass data to database

I am working on a mobile app and I have a scenario where the user upon selecting an image (For example: the mode of payment- credit card will have an image, money will have an image) thorough on-click function the color of the image should change and the data should be retrieved from database.
I am able to fix the on-click color change option but unable to access data from database. Please help me with this.
This is the code below:
<div class="container">
<table style="width:60%;text-align:center; ">
<thead>
<tr>
<td colspan="4" style="border-right:1px solid;">Mode of transport:(click to select)
</td>
<td colspan="2" >Mode of payment:(click to select)
</td>
</tr>
<thead>
<tr>
<td><img id="p2" src="./images/car_blue 120.png" style="width:60px;height:60px;" onclick="" />
</td>
<td>
<img id="p2" src="./images/Bus_blue 120.png" style="width:60px;height:60px; " onclick="" />
</td>
<td>
<img id="p2" src="./images/plane_blue 120.png" style="width:60px;height:60px; " onclick="" />
</td>
<td>
<img id="p2" src="./images/cash_blue 120.png" style="width:60px;height:60px; padding:5px;" onclick="" />
</td>
<td>
<img id="p2" src="./images/credit_card_blue 120.png" style="width:60px;height:60px; padding:5px;" onclick="" />
</td>
</tr>
</table>
</div>
Here You are talking about 2 different activity, It is not imp. that you are using Image/Button/or anything else. It only act as trigger to access database . It perform Some action after on click Event. " In your scenario action is "Retrieving Data"
If you provide clear info about Database type you are using , then it is easier to explain soln.
Your are in client side and you have to communicate with the server to access the data you need. if you want to communicate with remote server you will have to call web services in your app using javascript.
You have to invoke a function with onclick event which performs required action,for this you can use Ajax. Refer the discussion
connecting to an external databse with phonegap-android app
Use AJAX to populate Cordova database

how can I see the url output of submitted form?

there is a website and I want to create the link address that can automate the login process.
from the login page source code, I understood that it will submit the id, passwd values with post method in form.
but I want to know the entire 'url' address which this form submission leads to. I mean, eventually it will pass on the id, passwd values like in 'somewebpage?id=someid&passwd=somepw' right? (of course it will be processed with encodeURIComponent by the form)
this parameter included url address is what I'm looking for because I think if I know this, then I can automate the login process.
However, this address is not explicitly shown(not even for a brief moment). Is there a trick to somehow 'alert()' this url address or view it through chrome developer tools or something?
here's the login page example by the way:
<form id="login" name="login" class="login" method="post"
action="" enctype="application/x-www-form-urlencoded"
style="background-image: url(../main/image/index.gif)">
<input type="hidden" name="url" value="../main/index.cgi" />
<table class="login-form">
<tr>
<td>
<table>
<tr>
<td class="label"><label for="login_id">ID</label></td>
<td class="input">
<input type="text" id="login_id" name="id" value="" onclick="select();" maxlength="8"/>
</td>
</tr>
<tr>
<td class="label"><label for="login_passwd">Passwd</label></td>
<td class="input">
<input type="password" id="login_passwd" name="passwd" value="" onclick="select();" maxlength="8"/>
</td>
</tr>
</table>
</td>
<td>
<input type="submit" id="login_submit" value="Go" />
</td>
</tr>
<tr>
</tr>
</table>
</form>
You should be able to see the POST url in firebug net panel.
Form action attribute defines where the form will be submitted.
<form action="demo_form.asp" method="get">
The current form you have will submit to it self, meaning the current url the form is now on.
You can see the page properties from chrome developer tools network tab.
When there is no url in action the page, the form will post to itself. So all you would need to do is post the username and password to this page using the name of the input. On the server side, the username and password will be checked against the DB. To automate the post process look at the function here: https://stackoverflow.com/a/133997/3402205

How to show the form on click of a button?

I am facing a problem. I have created a form where a user has to input the details about a candidate and also upload his/her image. The problem is that in the form there is a button that says "Click To Add More Candidate", so when this button is clicked the same form should reappear under a division called "moreCandidates". Now to achieve this how should I go about it? Things that are coming in my mind is as follows:
To create a function in javascript that exactly creates the form contents (ie. all the input fields,etc) and onclick of the button "Click To Add More Candidate", call the function under the mentioned division. I can do this as in the past I have done something very similar to this. However, this time I don't think it would be good idea to create the whole form again as I have written a PHP function in between to read a directory.
Or the second thought that I have is to have the form code written in a file called candidate.php and call that file with AJAX. The problem here could be that I might be calling the whole form again (whereas I just want to call the contents of the form like the candidate name, and other stuff)
I very confused at the moment, and help from you all would be greatly appreciated. Thanks in advance.
My html code:
<div id="candidateForm">
<table border="0">
<form method="post" action="formDetails.php" enctype="multipart/form-date">
<tr>
<td>Candidate Name:</td>
<td><input class="candidateForm" type="textbox" name="candidateName" placeholder="Candidate's Name"/></td>
</tr>
<tr>
<td>Enroll No:</td>
<td><input class="candidateForm" type="textbox" name="enrollNumber" placeholder="Enroll No"/></td>
</tr>
<tr>
<td>Candidate Image:</td>
<td><input class="candidateForm" type="file" name="candidateImage" placeholder="Select a Image"/></td>
</tr>
<tr>
<td>Cadidate Post:</td>
<?php
//This is the target folder that is going to be read.
$target="uploads/";
//I an using a directory function in PHP scandir() which scans tha contains of the give directory
$dir=scandir($target);
?>
<td>
<select name="candidatePost">
<option value="candidatePost" select="selected">---------Select---------</option>
<?php
foreach($dir as $folders)
{
//When we loop throung the target folder/directory we get this annoying two folder that is "." and ".." so just to rule then out i m using an IF condition
if($folders!="."&& $folders!="..")
//echo $folders;
echo "<option class='candidateForm' value=$folders>$folders</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>About The Candidate:</td>
<td><textarea name="aboutCandidate" cols="40" rows="5"></textarea></td>
</tr>
<div id="moreCandidates"> </div>
<tr>
<td></td>
<td><input type="button" value="Click To Add More Candidate"></input> </td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="candidateFormSubmit" value="Press Here To Submit The Details" onclick=""/></td>
</tr>
</form>
</table>
</div>

Categories