Get the content of an <input> textbox with Python - python

I'm using a Tornado server running with Python, whose job in convert a .svg file in several font formats. For now I managed to make it generate a fontpack in a .zip file by clicking on a button. My Python code links with html form by using self.request.files['filearg'] where filearg is the name of the file selected in an <input type="file"> box.
But I'd like to make this submit button communicate with a text box in which I'd fill the output format I want my file converted in.
Basically, what I'd want in my html form would look like this:
<form enctype="multipart/form-data" action="/upload" method="post">
File: <input type="file" name="filearg" />
<input type="text" value="" name="format"/>
<input type="submit" value="Generate font(s)" />
</form>
I managed to do it with a Node.js server (with fields.format and so on), but I can't find any way to do this in Python.
I've heard about the CGI forms in HTML, which can permit to get this kind of content. But as if it's not the kind of form I chose, I wonder whether it can be implemented with my actual form.

The Tornado documentation explains how to get the values of form fields, using get_argument:
format = self.get_argument("format")

Related

How do I link a button in html with my python code? (django)

I'm working with django and I want to calculate something depending on what the user put on the selectboxes of my page, but I don't know how to connect that with my python code that calculates everything, please help :(
You can use a html form element like this with method post and action="path_of_your_python_file"
<form name="search" action="calculate.py" method="GET">
Search: <input type="checkbox" name="user_input">
<input type="submit" value="Submit">
</form>
Then in calculate.py
import cgi
form = cgi.FieldStorage()
searchterm = form.getvalue('user_input')
// Do your calculation here
I think that will help

HTML - Python How to access form elements?

Trying to build my own webmail client.
I get a template for the web part which look like this
<form name="input" action="test2.py" methog="get" class="form">
<input type="text" name="Username" placeholder="Username">
<input type="password" name="Pass" placeholder="Password">
<button type="submit" id="login-button">Login</button>
</form>
Would like to get the input on click on the button of Username && Pass via GET method to fill this bunch of code in python.
user = ???(Username)
pass = ???(Pass)
And print to a new empty html file the value of thoses var.
New to python so everything I try seem to fail.
You should use method="post", it won't work with a GET method (however it is misspelled, you wrote "methog").
Write import request without quotes at the top of your python file.
Now use request.inputForm['name'] without quotes to access form elements where name is the element name.

Capture HTML textbox value in python without CGI

I need to get the user input in a textbox and process it using my python script when user presses Submit button. Unfortunately I am using an external server that does not support CGI. Is there any other way I can do this? This is my sample HTML.
<body>
<form name="form1" method="post" action="script1.py">
<div id="heading"><big><big><big>My analysis</big></big></big></div>
<textarea cols="50" rows="1" name="Query_text" id="Query_text"></textarea>
<div id="Button"><input name="Submit" value="Submit" type="submit"></div>
</form>
</body>
You can do the form processing with Javascript but hopefully you don't want to save this input beyond the next page the person accesses. Another old school option is emailing yourself the contents of Query_text. But honestly this is a lot more work than you want to do and not worth the effort (for most people). What you need is a new web host.

Using button on a page with python

I am scraping a page for some data, however I need to insert text into a text box, submit the form and scrape the result page. I looked at the page source, but I'm not sure how to activate the button or pass down the argument for it.
Website is http://archive.org/web/web.php
Trying to look at some historicals, and no idea what to use for this. Open to any solution
First you should know that click on that button usually does a POST to some urls, passes the data in that form, here is:
<form id="wwmform" name="wwmform" method="get" action="http://web.archive.org/form-submit.jsp" onsubmit="document.location.href='http://web.archive.org/web/*/'+document.getElementById('wwmurl').value;return false;" style="display:inline;">
<input id="wwmurl" type="text" name="url" size="50" value="http://">
<button type="submit" name="type" value="urlquery" class="roundbox5">Take Me Back</button>
</form>
you see the action attribute? That's where the data goes to.
So in python, you may need urllib and urllib2 to encode the data and post it to the target url and then fetch the outcome.
ps: watch out the onsubmit

Python - posting checkbox to web form

i use this code in python to post something to a form in a web page.
but i dont just want to send some text as an input textbox, i also want to decide if a checkbox in the form is checked or not.
what value do i have to give to the 'checkbox' parameter in the "web_form"?
web_form = [('textbox', text),('checkbox', ?????)]
form_data = urllib.urlencode(web_form)
o = urllib2.build_opener(url)
res = o.open(url, form_data).read()
this is the html of the form:
<form action="?" method="POST" enctype="multipart/form-data">
<textarea name="textbox"></textarea> Checkbox <input type='checkbox' name='cb' > <input type="submit" value="submit" /></div>
</form>
You question is pretty broad since you did not mention with web framework you are using.
Application code could check either for the existence of the checkbox key in the request or check for a particular value...unless you provide further informations: try setting it to something like '1' and see what's happening.

Categories

Resources