Re: [semi-OT]simulating onSubmit in post
Hi Devin - I for one don't think this is OT at all: I have struggled to understand how to extract stuff from web sites in a more complicated way than the simple examples given in the Rev documentation. I got a lot of help from this list (especially from SparkOut sparkout...@gmail.com) but I still remain profoundly ignorant. For instance, I wanted to know in a similar situation if I could effectively by-pass the JS function while capturing the web-based data and then replicate its functionality within my Rev program. IMHO anything that sheds light on the kind of topic would help strengthen the use of Rev in the area of interacting with web services, so must be of interest to many Revvers. I hope to see some informative replies soon. Graham On Tue, 23 Feb 2010 16:11:25 -0700, uDevin Asay devin_a...@byu.edu wrote: Hi folks, I'm trying to teach myself how to GET and POST submissions to URLs that provide simple web services, like word lookups and the like. I understand the basic concept pretty well and can successfully harvest data from various web forms. But I notice that often POST method forms use JavaScript calls to validate data in the forms before submitting it to the server. It might look like this: form method=POST action=someurl.htm?loadpage name=formname onSubmit=return Validate(this); In this case the Validate function is defined in the header and basically returns true if the submit came from the form formname AND all of the fields are filled in. It returns false if either of these conditions is not met. My question: Is it possible to construct a post command and/or header combination that simulates this onSubmit event returning true? This is basically an academic exercise to help me understand how JS and forms work, and how Rev's GET and POST functionality works; I'm not planning to distribute stacks that do this in any way. Regards, Devin Devin Asay Humanities Technology and Research Support Center Brigham Young University ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: [semi-OT]simulating onSubmit in post
Hi Devin, In the url instanced below, unless I'm misunderstanding what you are trying to do, if you make a properly formed POST direct to someurl.htm?loadpage, direct from a script or a stack for instance, the onSubmit event in the html form is almost certainly irrelevant, because it is only triggered in the browser when the user clicks the submit element, and wouldn't apply in other cases. Have you experienced some issue that makes you think it is relevant? javascript validation can stop the form data being POSTed by the browser if something is wrong with user input or whatever, but you would bypass that by POSTing directly to the action url. Javascript pre-validation can manipulate the form data or perhaps set headers before it allows the POST action, and that might conceivably be relevant to it being accepted as valid by the action url. But it isn't very likely and in any case you should be able to figure the details out by reading the javascript to see what happens. Any serious validation will invariably be done by the script the data is POSTed *to* (the action url), unless the author is naive. Javascript validation (pre-validation) is really only useful for catching obvious data entry errors for purposes of user-friendliness. Martin Baxter Devin Asay wrote: Hi folks, I'm trying to teach myself how to GET and POST submissions to URLs that provide simple web services, like word lookups and the like. I understand the basic concept pretty well and can successfully harvest data from various web forms. But I notice that often POST method forms use JavaScript calls to validate data in the forms before submitting it to the server. It might look like this: form method=POST action=someurl.htm?loadpage name=formname onSubmit=return Validate(this); In this case the Validate function is defined in the header and basically returns true if the submit came from the form formname AND all of the fields are filled in. It returns false if either of these conditions is not met. My question: Is it possible to construct a post command and/or header combination that simulates this onSubmit event returning true? This is basically an academic exercise to help me understand how JS and forms work, and how Rev's GET and POST functionality works; I'm not planning to distribute stacks that do this in any way. Regards, Devin -- I am Not a Number, I am a free NaN ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
Re: [semi-OT]simulating onSubmit in post
On Feb 23, 2010, at 3:11 PM, Devin Asay wrote: Hi folks, I'm trying to teach myself how to GET and POST submissions to URLs that provide simple web services, like word lookups and the like. I understand the basic concept pretty well and can successfully harvest data from various web forms. But I notice that often POST method forms use JavaScript calls to validate data in the forms before submitting it to the server. It might look like this: form method=POST action=someurl.htm?loadpage name=formname onSubmit=return Validate(this); In this case the Validate function is defined in the header and basically returns true if the submit came from the form formname AND all of the fields are filled in. It returns false if either of these conditions is not met. My question: Is it possible to construct a post command and/or header combination that simulates this onSubmit event returning true? This is basically an academic exercise to help me understand how JS and forms work, and how Rev's GET and POST functionality works; I'm not planning to distribute stacks that do this in any way. First some tidbits to think about in order to answer your question (skip to the last couple paragraphs if you wish) When a web page loads, it is like a stack opening in Rev. Events trigger 'messages' (function calls) that load CSS code, the results of PHP code that runs on the server, JS functions, and many others. Some JS functions will run 'on openstack' and set variables (like Rev 'globals') which remain available as long as you stay on this web page. Some JS functions are in memory and get triggered on mouseup, mouseEnter, mouseLeave, click, openfield, closefield, etc Using FireFox and the FireBug add-on, you can see all of the scripts that are loaded in a broswer, and debug them step-by-step if you wish. FirePHP can do the same for php scripts. Because of security rules and conventions to protect server attacks, user-browser-globals are not a good thing to be kept between pages, so the site programmer uses cookies (client-side) or session variables (server-side) as a tracking mechanism. Many users add functions to their browser to make it more secure and these detect web pages that try to run malicious scripts or keep globals from page-to-page or do pop-ups, etc. And now on to forms. Form validation can be programmed by the web guy a few ways. The slowest is to have the FORM submit data and the server script do the work (server-side), returning a result to the browser and causing a reaction accordingly. The fastest is when the page is programmed with JS that does the same work on the local machine (client-side) because the server is not involved. A third way is to be using AJAX, which interacts with the server-side script after each keystroke (eg. Google search suggestions as you type). Simulating 3 types of forms: server-side FORM The way I use is to go into FireFox, activate the add-on using menu Tools:Live HTTP Headers, fill in the form, then capture the headers that are send by the browser. The headers will include the GET and POST data (of course). Now you can use Rev to manipulate the Headers (see the Rev dictionary) before submitting a form. client-side JS This step is done locally and usually only sends data to the server when there are no errors. If there is an error, the JS usually modifies the current web page indicating the corrections required. After all errors are fixed, the submit will allow capture of the Headers and you can see the GET/POST variables AJAX server-side This is a system of calls to the server triggered by some event, such as keystroke and blur/focus changes, so that the users input triggers changes in the web form. This is commonly used in airline and hotel reservations pages so that dropdowns and options trigger the appropriate form values for the user (eg. discounts available, seats available, rental car packages, black out days) Again, Live HTTP Headers can be used to capture, but now you will have numerous events to compile by reading the headers sent and received by the browser. You can choose to save a log of these transactions and study them. The downside is that you will not know all of the variations until you try them on the web page (eg. airline ticketing and flights available, a calendar that starts with today) because they are dynamic conditions. The first two are easily simulated with a Rev post command, but the third would require using the form, and scripting some arcane variations to test the return values. One way of capturing the GET/POST variables using Rev is to change the action=someurl.htm?loadpage to your own Rev cgi/OnRev script and parse the headers and variables yourself, but I find Live HTTP Headers more convenient for sleuthing, especially Authorization headers. By the way, Live HTTP Headers should work just as well when
Re: [semi-OT]simulating onSubmit in post
Thanks, Graham, Martin and Jim for your thoughtful and most helpful replies. Let me respond to a few of your points. On Feb 24, 2010, at 2:26 AM, Graham Samuel wrote: I for one don't think this is OT at all: I have struggled to understand how to extract stuff from web sites in a more complicated way than the simple examples given in the Rev documentation. I got a lot of help from this list (especially from SparkOut sparkout...@gmail.com ) but I still remain profoundly ignorant. For instance, I wanted to know in a similar situation if I could effectively by-pass the JS function while capturing the web-based data and then replicate its functionality within my Rev program. IMHO anything that sheds light on the kind of topic would help strengthen the use of Rev in the area of interacting with web services, so must be of interest to many Revvers. Since I am teaching my students about this topic this year, I am trying to distill what I am learning on my revolution.byu.edu web site. I have posted the following inter-linked pages that deal with GET and POST and Rev: http://revolution.byu.edu/internet/webServices.php http://revolution.byu.edu/internet/webServicesTerms.php http://revolution.byu.edu/internet/getMethodSteps.php http://revolution.byu.edu/internet/postMethodSteps.php http://revolution.byu.edu/internet/aboutForms.php I hope that others may find them informative (and that others won't be shy about pointing out errors if they find them.) On Feb 24, 2010, at 2:39 AM, Martin Baxter wrote: In the url instanced below, unless I'm misunderstanding what you are trying to do, if you make a properly formed POST direct to someurl.htm?loadpage, direct from a script or a stack for instance, the onSubmit event in the html form is almost certainly irrelevant, because it is only triggered in the browser when the user clicks the submit element, and wouldn't apply in other cases. Have you experienced some issue that makes you think it is relevant? Comments about JS client-side vs. server-side validation clipped. Thanks, Martin. That is what I suspected, but being a JS novice, it was helpful to have it confirmed. I had thought I had carefully parsed the form tag on the page in question and replicated the required arguments in my stack. However I still couldn't get the server to respond with the desired information. As it turns out then, the validation function was a red herring, and I discovered the problem after reading Jim Ault's enlightening reply. He gave a very helpful summary of various types of validation using server-side forms, client- side JavaScript, and AJAX server-side live-typing validation. But this bit of advice is what helped me find my error: On Feb 24, 2010, at 3:58 AM, Jim Ault wrote: server-side FORM The way I use is to go into FireFox, activate the add-on using menu Tools:Live HTTP Headers, fill in the form, then capture the headers that are send by the browser. The headers will include the GET and POST data (of course). Now you can use Rev to manipulate the Headers (see the Rev dictionary) before submitting a form. Once I installed Live HTTP Headers in Firefox, I could clearly see that I had failed to find some of the required arguments when I first looked through the form tag in the page source. I went back to the page source, and sure enough, found some hidden inputs that the page author had included after the submit input, but before the closing / form element. Nearly all of the other forms I've looked at have the submit input as the very last element in the form. So what tripped me up was a (to me at least) oddly-written form element in the page source. Thanks, Jim, for the tip on a very helpful tool. And thanks again everyone for your help. Regards, Devin Devin Asay Humanities Technology and Research Support Center Brigham Young University ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution
[semi-OT]simulating onSubmit in post
Hi folks, I'm trying to teach myself how to GET and POST submissions to URLs that provide simple web services, like word lookups and the like. I understand the basic concept pretty well and can successfully harvest data from various web forms. But I notice that often POST method forms use JavaScript calls to validate data in the forms before submitting it to the server. It might look like this: form method=POST action=someurl.htm?loadpage name=formname onSubmit=return Validate(this); In this case the Validate function is defined in the header and basically returns true if the submit came from the form formname AND all of the fields are filled in. It returns false if either of these conditions is not met. My question: Is it possible to construct a post command and/or header combination that simulates this onSubmit event returning true? This is basically an academic exercise to help me understand how JS and forms work, and how Rev's GET and POST functionality works; I'm not planning to distribute stacks that do this in any way. Regards, Devin Devin Asay Humanities Technology and Research Support Center Brigham Young University ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-revolution