Thanks for the help.
the problem was here.
form = cgi.FieldStorage()
As I mentioned in your answers, I typed in a โform,โ and it says โFieldStorage (None, None, []).โ
So, if FieldStorage doesn't matter, then it doesn't matter which function is used to get the form value. But it was really good information and practical.
previously, form = cgi.FieldStorage() was declared inside another function that was incorrect, so FieldStorage was empty.
Here is the WRONG code.
def myfunction (): cgitb.enable() form = cgi.FieldStorage()
Solution 1:
form = cgi.FieldStorage() must define run () inside the function and pass this form as a parameter to another function to get the values โโof the form.
those.
def run(): cgitb.enable() form = cgi.FieldStorage() myfunction(form)
Now it works
def myfunction (form): name = form.getfirst('name', 'empty') id = form.getfirst('id', 'empty')
Solution 2:
form = cgi.FieldStorage() must be defined directly inside the main function, then you do not need to pass it as a parameter.
those.
if __name__ == "__main__": cgitb.enable() form = cgi.FieldStorage()
Now its work and form are available inside my function.
def myfunction (): name = form.getfirst('name', 'empty') id = form.getfirst('id', 'empty')
Thanks to everyone.
source share