how to modify text in html form from python

Mike Meyer mwm at mired.org
Fri Oct 21 15:34:35 EDT 2005


"Philippe C. Martin" <pmartin at snakecard.com> writes:

> PS: If my question is not clear, I am trying to "share" the form between the
> client and server.

Yes, your question is not clear. And this statement doesn't clarify
it. That you quoted the "share" shows you are probably aware of this,
if not consciously so.

> just as many sites out there allow you to modify existing data:
> 1) the server pops up a form with your data in it.
> 2) the client can modify it and submit.

This doesn't really help, either. The server can't "pop up" a form;
only the client can do that. All the server can do is send data to
the client.

The client can't modify data on the server. It can send data to the
server, but that arrives as *new* data. The server can use that to
replace old data, thus modifying that old data.

> I know this is a _basic_ question, sorry.

It's not clear it's a basic question, because it's not clear what
you're trying to do.

Try answering these questions:

Where do you expect the HTML to come from?
Where do you expect the data originally in the HTML form to come from?
Where do you expect the data the user inputs into the form to be stored?

      <mike


> Philippe
>
>
>
> Philippe C. Martin wrote:
>
>> Hi,
>> 
>> I am trying to change the data in a form field from python. The following
>> code does not crash but has no effect as if "form" is just a copy of the
>> original html form.
>> 
>> Must I recreate the form order to do that ?
>> 
>> My point is for the client to be able to re-read the modified data.
>> 
>> 
>> Thanks,
>> 
>> Philippe
>> #!/usr/bin/python
>> 
>> import cgi
>> import os
>> import sys
>> import logging
>> import cgi
>> sys.stderr = sys.stdout
>> print "Content-type: text/html\n"
>> try:
>>     form = cgi.FieldStorage()
>>     #logging.warning (form)
>>     
>> except:
>>     logging.exception("\nEXCEPTION 1")
>> try:
>> 
>>     form['tosrv'].value = "TEST"
>> except:
>>     logging.exception("\nEXCEPTION 2")
>>     pass
>> 
>>     <html>
>>     <body>
>>     <title>Smart Logon</title>
>>     <h1>Smart Logon</h1>
>>     <hr>
>>     <FORM METHOD=POST ACTION="/cgi-bin/scfbweb.py">
>>     <table>
>>     <TR><TD>
>>       <INPUT TYPE=HIDDEN NAME="key" VALUE="process">
>>      TO SERVER:<BR>
>>       <INPUT  type=text NAME="tosrv" value="TO" size=60>
>>       <BR>
>>       FROM SERVER<BR>
>>       <INPUT type=text name="fromsrv" value="FROM" size=60>
>>       <P>
>>         <INPUT TYPE="SUBMIT" VALUE="START">
>> 
>>     </TD></TR></table>
>>         </FORM>
>> </body>
>> </html>
>

-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list