submitting form in auto it - html

The problem is :
I have form in html which contain :-
"two text-box" and " bottom to submit"
What I want is :
Make the script in automatically add some text and submit form without opening an internet explorer window (just the script).
I tried to implement a get and post, but it failed
#include<ie.au3>
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "http://localhost/2.html", False)
_IELinkClickByText( $oHTTP , "submit")
$oHTTP.Send()

You can do it with WinHttp.au3 - https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
Check on _WinHttpSimpleFormFill which fills a form and then submits

Functions with "_IE" prefix is not used for WinHttp object. So, you cannot call the _IELinkClickByText function.
Example using IE UDF to submit a form:
#include <IE.au3>
Local $oIE = _IECreate('http://localhost/2.html')
Local $oForm = _IEFormGetCollection($oIE, 0)
_IEFormSubmit($oForm)
But if you want to use WinHttp, you should use the POST method instead of GET.

Related

Flask: buttons with varying functions

I'm writing a program in flask. In one of the pages (/search), the user will have a field to enter a string and click a search button. The result page that follows works all right, which consists of an html page with several images on it.
Now i want to add a button next to each image that, once clicked, will add an item to my mongoDB database.
So, 2 problems:
1) The buttons i managed to create so far will demand a "return redirect(page)". I don't want that. The user must be allowed to click several buttons in sequence, instead of having to perform a new search.
2) i built my own mechanism for rendering the result.html page. According to the search results, my code opens result.html and writes (appends) the urls on it.
#app.route('/add', methods = ['POST'])
def add():
print "hi"
return None ##Python won't accept 'return None' here =(
[...]
w=open("result.html", "a")
[...]
for k in cursor:
try:
w.write(k['url'] + "'> <form action='/add' method='post'> \
<input type='submit' value='Add'></input></form>")
How can i make the button tell the /add view function know the url for each image? I suppose there is something i should replace in this last block of code.

<a data-method='something' href ... - POSTs?

yes, it does.
Is this any where documented?
Background: with my RoR Helper I made an error and created Links with data-method='GET'. Everthing still worked, only that I got a "Resend Data Warning" when refreshing the page ...
Now I found this strange behavior: data-method='GET'
Works with FF, IE, Chrome
Is this a standard? if yes it makes the Rails button_to (with all the form around) obsolette ...
edit: I forgott to say: _method is made out of data-method and this is as data posted, if i change the 'GET' to a - lets say 'PUT' I get RoR routing errors
an other edit: OK, I try too explain with a better example:
the following line
"<a data-method='PUT' href='?'>post</a>"
creates a POST request with _method='PUT' as data
no it is not a standard, as long as you say that RAILS Jquery_ujs.js is not a standard.
Rails/Jquery is doing this Magic:
if you take a look here all the magic is gone ...:
$.rails = rails = {
// Link elements bound by jquery-ujs
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with], a[data-disable]',
// Button elements bound by jquery-ujs
buttonClickSelector: 'button[data-remote], button[data-confirm]',
// Select elements bound by jquery-ujs
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
// Form elements bound by jquery-ujs
formSubmitSelector: 'form',
// Form input elements bound by jquery-ujs
formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
// Form input elements disabled during form submission
disableSelector: 'input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled',
// Form input elements re-enabled after form submission
enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled',
// Form required input elements
requiredInputSelector: 'input[name][required]:not([disabled]),textarea[name][required]:not([disabled])',
// Form file input elements
fileInputSelector: 'input[type=file]',
// Link onClick disable selector with possible reenable after remote submission
linkDisableSelector: 'a[data-disable-with], a[data-disable]',
// Button onClick disable selector with possible reenable after remote submission
buttonDisableSelector: 'button[data-remote][data-disable-with], button[data-remote][data-disable]',

Custom Input Names on GravityForms

How can I add custom input names to gravity forms? I need to submit a form to a third party service that requires very specific form names.
My current idea is to write a bit of jQuery to dynamically rename everything when the page loads. Obviously this isn't ideal.
Gravity Forms: http://www.gravityforms.com/
After contacting the makers of Gravity Forms, it sounds like they don't support custom input names. As a workaround, I wrote a bit of jQuery to rename inputs with the correct form names. For example:
$("input#input_1_1").attr("name","first_name");
Just put some code in functions.php and fill out the form which will then email you with a list of the id names, they are the same names that you can fine using developer tools etc. This was just faster for me. Then change the code to have it post via curl with different input names.
This uses php so it's on the server to handle. That way you don't have to worry about people with JS disabled in their browser.
http://0to5.com/gravity-forms-submitting-forms-to-3rd-party-applications/
Add a new field (HTML field). In content settings of this field add this javascript with script tags
Non-jquery solution:
document.getElementById("input_14_4").setAttribute("name", "email");
Another solution i found here
https://docs.gravityforms.com/gform_field_content/
add_filter( 'gform_field_content', function ( $field_content, $field , $value, $lead_id, $form_id) {
if ( $form['id'] != 14 ) {
//not the form whose tag you want to change, return the unchanged tag
return $field_content;
}
if ( $field->id == 3 ) {
return preg_replace( "|name='(.*?)'|", "name='email'", $field_content );
}
return $field_content;
}, 10, 5 );

Get HTML Content Upon Submit

In Jsp while i press submit button instead of passing values to action.
I want the HTML content of that form with all values it is possible??
If possible give an example. Let me know if any clarification is needed.
It isnt clear where do you need this html content?
If on browser, use an alert in an onSubmit event -
alert(document.myForm.innerHTML);
To get this on to server side, you will need to pass this content as part of form submission, maybe in a hidden field.
in onSubmit() event:
myForm.myHiddenHtmlContent = myForm.innerHTML;
For InnerHTML with current form values:
Its not plain easy, check out the following link -
innerHTML with current form values
This uses jquery, but you can also write your own without it as well.
Including an example -
Ok, it looks like it works in IE but not in FireFox. Basically you need to setAttribute('value') for each form element to make it work.
Use following -
var formElements = document.getElementById("myFormId").elements;
for (var x = 0; x <= formElements.length - 1; x++)
{
if (formElements[x].value) {
formElements[x].setAttribute("value", formElements[x].value);
}
}
//Now you are ready to call innerHTML
myForm.myHiddenHtmlContent = myForm.innerHTML;
Hope this helps.

Getting inputs inside of a form tag

I have a form with id and multiple inputs with ids as well how i get a specific input inside a form tag.
<form action="#" method="post" id="frm-location">
<input type="text" name="txt-location" id="txt-location" />
</form>
what I want is to get the txt-location from the frm-location
You want a reference to the <input> element itself?
var form = document.getElementById('frm-location'),
input = form.getElementsByTagName('input');
// or, more specifically:
var form = document.getElementById('frm-location'),
input = form['txt-location'];
// if the name didn't have a dash in it, you could write this instead:
input = form.txtLocation;
// or, even better, since the input has an ID:
var input = document.getElementById('txt-location');
https://developer.mozilla.org/en/DOM/document.getElementByID
https://developer.mozilla.org/en/DOM/element.getElementsByTagName
https://developer.mozilla.org/en/HTML/element/form
https://developer.mozilla.org/en/DOM/element
You want the value of that element?
var input = /* whatever */,
inputValue = input.value;
https://developer.mozilla.org/en/DOM/HTMLInputElement
HTML is a static type markup language. As such, by itself there are not many options for accessing and processing data. There are a few general approaches for getting data from a web page. I'll keep the explainations generic, but they will translate to whatever platform/language you are using.
Access the data server side. This is accomplished by having the user submit the form. Once submitted, the values will be available via the query parameters. Various languages will have different methods to access the parameters.
Access the data client side. You can always use javascript to hook client side events like onblur, onchange, onfocus. Once your javascript fires, you can access various form elements with dom/js methods like getElementById/getElementByName -- Which would be able to reference your form elements but Id/Name respectively.
A Hybrid approach. AJAX is a mixture of the two approaches listed above. Client side code (javascript) makes async calls to the server. the server then processes the data in some manner and sends responses back to the client.
Hope this points you in the right direction. If you would like to clarify your question a bit, I can certainly try to cater the answer more to your specific case.