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

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();

Related

Filling up form with predefined data in others website form

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)

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.

using one site's form from another

Currently, I have a site which uses services from a third party. A link takes me to the third party site where data is entered and processing occurs. My problem is that the third party site is ugly. The controls that they use are OK, but the display is terrible.
I would like to use their controls on my page, submit their form, retrieve their output, process it, and display it to my customers in the format that I prefer.
This would be straightforward if XmlHttpRequest worked across domains.
I am trying to decide how I can accomplish my goal. I am thinking perhaps a CGI script using cURL could act as an intermediary, but I am hoping there is something more straightforward.
Thanks.
Nothing more straightforward. Except for if you're satisfied with their results page, you can just put form on your side and specify action attribute pointing to their.
"I am trying to decide how I can accomplish my goal. I am thinking perhaps a CGI script using cURL could act as an intermediary, but I am hoping there is something more straightforward"
I think that this might be the only way to do it. That is, a script which will use curl to POST data to the form of the site you mention. Then it's up to you to process the response accordingly.

How do end users (hackers) change Jquery and HTML values?

I've been looking for better ways to secure my site. Many forums and Q/A sites say jquery variables and HTML attributes may be changed by the end user. How do they do this? If they can alter data and elements on a site, can they insert scripts as well?
For instance I have 2 jquery scripts for a home page. The fist is a "member only" script and the second is a "visitor only" script. Can the end user log into my site, copy the "member only" script, log off, and inject the script so it'll run as a visitor?
Yes, it is safe to assume that nothing on the client side is safe. Using tools like Firebug for Firefox or Developer Tools for Chrome, end users are able to manipulate (add, alter, delete):
Your HTML
Your CSS
Your JS
Your HTTP headers (data packets sent to your server)
Cookies
To answer your question directly: if you are solely relying on JavaScript (and most likely cookies) to track user session state and deliver different content to members and guests, then I can say with absolute certainty that other people will circumvent your security, and it would be trivial to do so.
Designing secure applications is not easy, a constant battle, and takes years to fully master. Hacking applications is very easy, fun for the whole family, and can be learned on YouTube in 20 minutes.
Having said all that, hopefully the content you are containing in the JS is not "mission-critical" or "sensitive-data". If it is, I would seriously weigh the costs of hiring a third party developer who is well versed in security to come in and help you out. Because, like I said earlier, creating a truly secure site is not something easily done.
Short Answer: Yes.
Anything on the users computer can be viewed and changed by the user, and any user can write their own scripts to execute on the page.
For example, you will up vote this post automatically if you paste this in your address bar and hit enter from this page:
javascript: $('#answer-7061924 a.vote-up-off').click();
It's not really hacking because you are the end user running the script yourself, only doing actions the end user can normally do. If you allow the end user on your site to perform actions that affect your server in a way they shouldn't be able to, then you have a problem. For example, if I had a way to make that Javascript execute automatically instead of you having to run it yourself from your address bar. Everyone who came to this page would automatically upvote this answer which would be (obviously) undesired behavior.
Firebug and Greasemonkey can be used to replace any javascript: the nature of the Browser as a client is such that the user can basically have it do anything they want. Your specific scenario is definitely possible.
well, if your scripts are public and not protected by a server side than the Hacker can run it in a browser like mozilla.
you should always keep your protected content in a server side scripting and allow access by the session (or some other server side method)
Yes a user can edit scripts however all scripts are compiled on the user's machine meaning that anything they alter will only affect their machine and not any of your other visitors.
However, if you have paid content which you feed using a "members-only" script then it's safest if you use technology on the server to distribute your members-only content rather than rely on the client scripts to secure your content.
Most security problems occur when the client is allowed to interact with the server and modify data on the server.
Here's a good bit on information you can read about XSS: http://en.wikipedia.org/wiki/Cross-site_scripting
To put it very simply:
The web page is just an interface for clients to use your server. It can be altered in all possible ways and anyone can send any kind of data to your server.
For first, you have to check that the user sending that data to your server has privileges to do so. Usually done by checking against server session.
Then you have to check at your server end that you are only taking the data you want, and nothing more or less and that the data is valid by validating it on your server.
For example if there is a mandatory field in some form that user has to fill out, you have to check that the data is actually sent to server because user may just delete the field from the form and send it without.
Other example is that if you are trying to dynamically add data from the form to database, user may just add new field, like "admin", and set it to 1 and send the form. If you then have admin field in database, the user is set as an admin.
The one of the most important things is to remember avoid SQL injection.
There are many tools to use. They are made for web developers to test if their site is safe. Hackbar is one for example.

What is a good way to get feedback from a user on a website?

I'm working on a website for my county's fair. I want to allow my visitors to be able to ask me questions by inputing their name, email, and comment in a form like this one:
http://lincolnfair.net/images/feedback.JPG
So I guess my real question is how can I send an email (using JavaScript/JQuery) to myself with all these fields as the main body of the email.
You should use a server-side script (e.g. PHP, Python, Perl, etc.). With pure HTML and JavaScript, you can use a mailto form, but this will be very unreliable.
I will suggest uservoice.com , it can integrate with your site nicely, a much more powerful user feedback system, without spending time to code the feedback system yourself
As others have indicated, this is a typical task that can be solved easily using a server-side language. Javascript and jQuery aren't the right tool for this particular problem. To point you in the right direction, use method="post" for your form, and you can access users' submission in a PHP file by examining the $_POST variable. If a <input> element in your form has name="email" in your email, you can access that variable in PHP as $_POST['email']. If you're interested in a PHP solution, look at the documentation for the mail() function.
Jukka has a good guide on How to write HTML forms. It should give you everything you need to produce something functional.
You need a server side component, nothing client side will be a reasonable substitute for that. JavaScript won't help for a form as simple as the one you describe.
The most reliable way will be to use a server side script in your preferred language. The specifics of how to do this are probably outside the scope of this question and would depend upon your language of choice.
Your other option is to set the action of the form as a mailto: which will use the visitors preferred email client to send the email. This will work but is really bad and relies on the viewer having an email client installed and configured.
you can find out more information about the mailto option at http://www.chami.com/tips/internet/010597I.html
Another good option would be a third party site such as www.wufoo.com which handle all of the email business server side for you on their own servers. I believe Wufoo even allow you to embed their forms within your own site.
If you want it to be available on every page, you might want to consider using jQuery and the UI Dialog plugin. You could set it up so that the default feedback is a mailto which gets replaced using javascript with a link that brings up a jQuery Dialog containing the fields you want to collect. This could be submitted back to your server via AJAX and delivered to you via email from the server.
EDIT: Since you've edited your question to indicate a server-side only solution, the above seems somewhat out of context. With others, I would agree that using some client-side code to actually send the email is the way to go (as alluded to above). I think it's preferable to use your own server for this, but I'm sure that you can find many "form to email" services. I would avoid these, unless you want your email addresses harvested for use in SPAM. You might also be able to use a signed applet or ActiveX control for this, again I would not go down that route. As indicated above, I would let the browser handle the interface, but my server handle the sending of the email.
I am not sure i understand your question completely, but if all you want to do is conduct a survey over email, i don't think you need to use jQuery or HTML.
A very simple way to do it is to use the 'Forms' feature in Google Docs.

Categories

Resources