正在返回从单选按钮选择只有第一个字

问题描述 投票:0回答:1

为了得到一个单选按钮的形式选择的选项,我看request.vars来获取值。以下是控制器代码:

def get_results():

test = request.vars['QuestionOne']

for topic in session.selectedtopics:
    test = test + request.vars[topic]

return locals()

而现在该视图的代码:

{{extend 'layout.html'}}

<P>Please select the options that most closely approximates the actual scenario.
<br>
<form action="{{=URL('get_results')}}" method="post">
    {{nameTopic =""}}
    {{session.selectedtopics = list()}}
    {{for topic in topics:}}
        {{if nameTopic <> topic.topic.replace(" ", "_"):}}
            <br><h2>{{=topic.topic}}</h2>
        {{nameTopic = topic.topic.replace(" ", "_")}}
        {{session.selectedtopics.append(nameTopic)}}
        {{pass}}
        <p><input type="radio" name={{=nameTopic}} value={{=topic.param}}>{{=topic.param}}</p>
    {{pass}}
    <br>
    <input type="submit">
</form>

这里的问题是:我不知道原因,但只获得无线电形式所选择的选项的第一个字。例如,选择的选项是“这是正常的”,但VAR仅返回“它”。任何想法,为什么这是怎么回事?

预先感谢。

radio-button web2py
1个回答
0
投票

你需要引用的HTML属性值:

<input type="radio" name="{{=nameTopic}}" value="{{=topic.param}}">

不带引号,你会最终HTML落得像:

<input type="radio" name=some_topic value=It is normal>

浏览器会解释的价值是“它”,用“是”和“正常”是无效的HTML属性。

© www.soinside.com 2019 - 2024. All rights reserved.