Filling up form with predefined data in others website form - javascript

I need to fill up form in another website which is not in my control. I have some datas filled in my website, I need to pass those data and fill the existing form in another website. Is it possible to fill the form using php, jquery?
For simplicity,
I want to redirect user after filling up form in my site abc.com save it in my database and redirect to external website xyz.com and fill the existing form there.

Your best bet would probably be to replicate their form 1:1 on your site and submit it using <form action="their_form_url">. This would work, however, only if they don't have XSRF countermeasures in place (most sites don't, some do).
You will not be able to manipulate the form with JavaScript in pretty much any way unless the iframe target (i.e., their site) is in your domain.
If you only want to fill the data in without submitting, you are out of luck. Both JS and cookies follow the same-origin policy, which explicitly dictates defenses against this kind of behavior.

It all depends on the target website. If they pre-fill their form with $_GET data or $_POST data, you can just pass on that data. A good shot may be to try to post wrong data (like a wrong captcha value) manually and see how they fill their form again. Maybe you could use that in your favor.
Although, another possibility is to load their site in an iframe, and put the data with Javascript, by accessing the iframe code. I'm not sure about this, though. I just think it can be done. (Please correct me, if I'm wrong)

Related

Passing variables between ASP MVC pages without sending it to server

I am creating a website with ASP.NET MVC 4. The application consists of two pages, whose workflow is similar to Google Maps. On the first page, the user types in a patient's name, date of birth, and some basic data about that patient. Then the user submits the form, and is brought to the second page in the application. The second page is just a print preview that the user can print. I want the user to be able to navigate between the two pages using the browser's back and forward buttons (for example, to change inputs on the first page after seeing the second page)
Actually calculating the data that appears on the printout is very complicated, and I really want to have all that code be executed server-side, where I can use C#. So I need to send the patient's data to the server. The problem is that I don't have an SSL certificate, and I don't want to send a patient's name with their data over HTTP (as this is a violation of privacy). I am willing to send the patient's data over HTTP, as long as it remains detached from the patient's identity (except for at the client). The name and date of birth are simply displayed in the corner of the printout, and do not affect the server-side calculations in the least.
I can think of two possible ways to accomplish this task. The first, more preferred solution, would be a way to send only some of the form data over HTTP, yet still somehow get the name and date of birth from the first page in client-side jquery running on the second page. Maybe I can make a cookie and somehow specify not to send it as part of the http request?
The other way to accomplish this is to make the entire application into a single page, and dynamically change the contents via client-side jquery. In this solution, when the user submits the form, I can fire off an ajax request that will return JSON. I can then populate the print preview with data returned from the server (i.e. the JSON) as well as from the form (i.e. the patient's name and date of birth). Is there a way to accomplish this while still allowing the user to use the browser's back and forward commands to navigate between the data input page and the print preview page if they are in fact the same page?
I don't believe what you described is possibly without severe drawbacks. Sure, you could roll up the data into a cookie or local storage and avoid the POST--but this is a lot of logic in your view, and a pretty nasty hack.
The options I would advise are:
Get an SSL cert. If that's the driving force behind your approach then spend the $6 to get one. Seriously.
Keep the print view in the same page as the form; use css #media types to specify the print styles.

Avoiding html form input manipulation

I have several forms which contains data fetched from Google Directions Service (JS API), distance for example is especially important to me.
Sure, I know that I cant really prevent user from messing with the data in input fields, what I am asking is if there is some technique to make submitting manipulated form painful enough to stop people trying.
My hopes arent too high on this but I want to make sure before I get into some server-side solution.
Thanks in advance.
Since you are just getting data via the JS API and do not need any changes to those from user, how about sending the data to Server over AJAX calls as and when it is received perhaps with some your own simple encryption. This would certainly increase the number of requests but depending on the amount of data, it can work out for your usecase. Even if you would want to post some form data from the same page, it could be attached to a user's session on the server.
Please note that this is not fool-proof with firebug and the likes but gets more difficult for someone to play with the values.
try using hidden input fields:
<input type="hidden">
These get submitted to the server but are not visible to the user.

Keep form data on page refresh

I have a situation where for some reason a Web page might refresh while a user is filling out a form. The unwanted effect is to wipe out the data already entered by the user.
Is there a solution to have the form data persist on page refresh?
The form includes text input and selects.
You say "I have a situation where for some reason a Web page might refresh", do you mean that the user might refresh the page, or is it some other script that refreshes the page? If the case is the latter, you should probably try to fix the issue that causes the refresh instead of trying to preserve the form data. If it is the former, JavaScript will probably be the solution for you.
You could listen for every keyup-event on any of the form elements. When a keyup-event is fired you serialize the form data and write it to a cookie (or a webstorage, depending on what browsers you need to support), to preserve the most up-to-date data. If the page reloads, or if the user leave the page and comes back, the cookie can be deserialized on document-ready, and you can re-populate the form with the data from the cookie. When you post the form, you make sure to also clear the cookie, to make sure the form isn't filled the next time the user loads the page.
Update
Here is a good blog post about how to use GSerializer for serialization an deserialization with JavaScript.
A suggested approach
As the user is filling out the form, have JavaScript running that caches the entered values in LocalStorage, a cookie, or a session variable via AJAX.
On page load, check for the presence of these entries, and populate the form with JavaScript.
On form submit, clear the entries.
Use HTML5 web storage- it is faster and more secure than cookies. You can check out the W3Schools website for some quick and basic samples: http://www.w3schools.com/html5/html5_webstorage.asp

How to store a Web page in localStorage to view at any time

I have a online web application form which I have to open every time and have to fill data and Submit.. So, I have got an idea of making a Google Chrome extension, that will make that page stored inside localStorage So that I can access it like a desktop page.. Is this possible.. I do not have any permissions to change the web site at server side.. I am just a client side programmer.. Is it possible? if yes please let me know how can I achieve this..
in theorie, yes, you could. Practically, it won't work out like you want. The reason are the external resources the website is going to be needing.
Storing just the html (document.body.innerHTML) would be possible. BUt if you want the formatting/layout to be happening, you'd need to save the computedStyles for each element as well. And if an image, you'd need to Base64 encode the image and save it.
Even if you'd succeed in saving the page, you'd need to know when to expire your localStorage cache and refetch the resources to stay compliant to the server side parsing of the form data (if they'd change something).
if its just about submitting a form, you also could just trigger the forms post-action-url directly by writing a script that resends the data you want sent.

auto fill fields and submit from another server, is it posible?

let's assume there is a site http:/ /testsite.com, with some filds and submit button.
Is there a way, to write a javascript script, which will fill all filds with values i want, and make submit operation automaticaly?
Is it possible, maybe there is some documentation about it?
Thanks
UPDATE
i don't have access to the script of site, i must make it from another server.
Do you mean a site that is not your own? Like, you want to embed another site's form into your webpage and then auto-fill some values? No, generally speaking this cannot be done because of the same-origin policy. The best you could do is proxy for that site, e.g. your web server can fetch the form, fill out values and present that to your users. This won't work (or, not very well) if the other site requires authentication.
Maybe you're looking for something like Selenium, which can record your actions (using a browser plugin), save them as test scripts, and replay them later.
Another option would be to craft a custom POST request using CURL, or create your own form that submits to the page that handles the form on testsite.com.
It really depends on what you're trying to accomplish.
Sure, try this:
$('form').filter('input').each(function() {
$(this).val('Some value');
}).end().submit();

Categories

Resources