Send a form with a radio button ?

已查看 118 次
跳至第一个未读帖子

Jason

未读,
2020年6月16日 08:05:032020/6/16
收件人 cherrypy-users

I would like to make a radio button which loads either one page or another without using a submit button. By clicking on site 1 or site 2... 

Python via cherryPy will send the correct html. My problem and therefore how to send the value of radio buttons without using a send button or java, ...

How can the form be sent just at the click of a radio button ?


Python :

import cherrypy,os

class Web(object):
    'web'
    def index(self):
        'Page'
        return open("teste.html")
    index.exposed = True

    def site(self,s):
        'Formulaire'
        if s == 1:
            return open("teste1.html")
        elif s == 2:
            return open("teste2.html")
        elif s == 3:
            return open("teste3.html")
    site.exposed = True


if __name__ == '__main__':

    cherrypy.config.update({"tools.staticdir.root": os.getcwd()})
    cherrypy.quickstart(Web(), config="id_serveur.conf")

yes i could use

<a href="..."> ... </a>

but this is just an example for the radio button to send its form



HTML

<!DOCTYPE html>
<html lang="fr">
    <head>
        <meta charset="utf-8">
        <link type='text/css' rel='stylesheet' href="teste.css"/>
    </head>

    <body>
        <center>
            <div>
                <form name="site" action="/site" method="post">
                    <input type="radio" name="s" value="1" id="m1">
                    <label for="m1">Site 1</label>
                    <input type="radio" name="s" value="2" id="m2">
                    <label for="m2">Site 2</label>
                    <input type="radio" name="s" value="3" id="m3">
                    <label for="m3">Site 3</label>
                </form>
            </div>
        </center>
    </body>
</html>

If someone has an idea ??? he tell me about event but apart from java and jQuery. I can't find the solution for python ???

guangge

未读,
2020年6月16日 22:41:562020/6/16
收件人 cherryp...@googlegroups.com

You can use */** to test as this:

def site(self, *k, **kw):

print(‘k, kw: ‘, k, kw)

 

/a/b?c=7&d=8&d=9

(‘a’,’b’), {‘c’:’7’, ‘d[]’:[‘8’,’9’]}

 

So you can do as this :

def site(self, s):

         filename=’test%s.html’ % s

         return open(filename)

 

<a href=”1”>test1</a>

<a href=”2”>test2</a>

 

Or as this:

def site(self, s=1):

filename = ‘test%s.html’ % s

return open(filename)

 

<a href=”?s=1”>test1</a>

<a href=”?s=2”>test2</a>

 

发件人: guangge77+caf_=yaoguangming.cq=chinate...@gmail.com [mailto:guangge77+caf_=yaoguangming.cq=chinate...@gmail.com] 代表 Jason
发送时间: 2020616 18:54
收件人: cherrypy-users
主题: [cherrypy-users] Send a form with a radio button ?

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/30b11f5e-da1c-4f15-a382-a0e942af2d25o%40googlegroups.com.

Tim Roberts

未读,
2020年6月17日 01:10:172020/6/17
收件人 cherryp...@googlegroups.com
On Jun 16, 2020, at 3:54 AM, Jason <jason7...@gmail.com> wrote:

I would like to make a radio button which loads either one page or another without using a submit button. By clicking on site 1 or site 2... 

Python via cherryPy will send the correct html. My problem and therefore how to send the value of radio buttons without using a send button or java, ...

There is no Java in a browser.  Do you mean Javascript?  The two languages are not related, and you need to be careful when you use the names.

How can the form be sent just at the click of a radio button ?

...

If someone has an idea ??? he tell me about event but apart from java and jQuery. I can't find the solution for python ???

Javascript is the right answer.  That’s what it’s FOR.  Javascript runs in the user’s browser, and can take actions without requiring and network exchanges.  Your Python code runs on your server.  You can respond to clicks, but you can’t force the page to click anything.
— 
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Tim Roberts

未读,
2020年6月17日 01:10:192020/6/17
收件人 cherryp...@googlegroups.com
On Jun 16, 2020, at 3:54 AM, Jason <jason7...@gmail.com> wrote:

I would like to make a radio button which loads either one page or another without using a submit button. By clicking on site 1 or site 2... 

Python via cherryPy will send the correct html. My problem and therefore how to send the value of radio buttons without using a send button or java, ...

There is no Java in a browser.  Do you mean Javascript?  The two languages are not related, and you need to be careful when you use the names.

How can the form be sent just at the click of a radio button ?

...

If someone has an idea ??? he tell me about event but apart from java and jQuery. I can't find the solution for python ???

Javascript is the right answer.  That’s what it’s FOR.  Javascript runs in the user’s browser, and can take actions without requiring and network exchanges.  Your Python code runs on your server.  You can respond to clicks, but you can’t force the page to click anything.
— 

Jason

未读,
2020年6月17日 10:01:492020/6/17
收件人 cherrypy-users

So you can do as this :

def site(self, s):

         filename=’test%s.html’ % s

         return open(filename)

 

<a href=”1”>test1</a>

<a href=”2”>test2</a>

 

Or as this:

def site(self, s=1):

filename = ‘test%s.html’ % s

return open(filename)

 

<a href=”?s=1”>test1</a>

<a href=”?s=2”>test2</a>


Thank you for your answer so I must transform my radio button into 

Jason

未读,
2020年6月17日 10:05:282020/6/17
收件人 cherrypy-users
Javascript est la bonne réponse. C'est pour ça. Javascript s'exécute dans le navigateur de l'utilisateur et peut prendre des mesures sans nécessiter ni échanges réseau. Votre code Python s'exécute sur votre serveur. Vous pouvez répondre aux clics, mais vous ne pouvez pas forcer la page à cliquer sur quoi que ce soit.

I wanted to avoid JavaScript

Tells you I can respond to the click ???

How to send the click of the radio button to the server ? 

Tim Roberts

未读,
2020年6月17日 14:48:252020/6/17
收件人 cherryp...@googlegroups.com
Jason wrote:
Javascript est la bonne réponse. C'est pour ça. Javascript s'exécute dans le navigateur de l'utilisateur et peut prendre des mesures sans nécessiter ni échanges réseau. Votre code Python s'exécute sur votre serveur. Vous pouvez répondre aux clics, mais vous ne pouvez pas forcer la page à cliquer sur quoi que ce soit.

I wanted to avoid JavaScript

Why?  That's not a sensible restriction.


Tells you I can respond to the click ???
How to send the click of the radio button to the server ?

You cannot do so.  Without using Javascript, the only way to get requests to the server is for the user to click a submit button or click in an <a href> link.  Remember, your Python code is not running in the server.  The browser is in control.  The only communication your server gets is when the browser decides to send you something.

-- 
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Jason

未读,
2020年6月17日 19:08:472020/6/17
收件人 cherrypy-users

You cannot do so.  Without using Javascript, the only way to get requests to the server is for the user to click a submit button or click in an <a href> link.  Remember, your Python code is not running in the server.  The browser is in control.  The only communication your server gets is when the browser decides to send you something.

-- 
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.


Thank you, Python is the first language I'm learning, as an autodidact, that's why i didn't want to go through another language

But that's for sure JavaScript and made for the WEB ^^

        Thank you
回复全部
回复作者
转发
0 个新帖子