2016-08-30 5 views
0

を何も返しません。値を取得するとき:HTMLフォームは、私は私のHTMLにこのフォームを持っている(ChromeでOK)のFirefox&IEに

vote = self.request.get('vote') 

「up」または「down」のいずれかが表示されます。

しかし、IEとFirefoxで同じことをすると、空の文字列が結果として得られます。

(HTMLのif/elseステートメントは、ユーザーがまだその特定のコンテンツに投票していない場合、アイコンが灰色で表示されることを意味します。そうでない場合は黒です)。

Google App EngineでJinja2をテンプレートエンジンとして使用しています。

+0

あなたは ' mplungjan

+0

はい、それはそのように動作します。これは、押されたときにフォームを送信するアイコンです。しかし、vote = "up"かvote = "down"のどちらかでなければなりません。 –

答えて

0

これを試してください。代わりに、ボタンを使用して、画像を使用する:

<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_up %} 
    <input type="image" src="icons/thumb-up.png" alt="Up!" name = "vote" value = "up" /> 
    {% else %} 
    <input type="image" src="icons/thumb-up_gray.png" alt="Up!" name = "vote" value = "up" /> 
    {% endif %} 
    <input type="hidden" name = "vote" value = "up"/> 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 
<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_down %} 
    &nbsp;<input type="image" src="icons/thumb-down.png" alt="Down!" name = "vote" value = "down" /> 
    {% else %} 
    &nbsp;<input type="image" src="icons/thumb-down_gray.png" alt="Down!" name = "vote" value = "down" /> 
    {% endif %} 
    <input type="hidden" name = "vote" value = "down"/> 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 

<style>button {height:32px; width:32px;}</style> 

<form action="/vcontent?topic={{ topic.name }}" method="post"> 
    {% if user and user.email in c.users_up %} 
    <button type="submit" style="background: url(icons/thumb-up.png)" title="Up!" name="vote" value="up" /> 
    {% else %} 
    <button type="submit" style="background: url(icons/thumb-up_gray.png)" title="Up!" name="vote" value="up" /> 
    {% endif %} 
    {% if user and user.email in c.users_down %} 
    &nbsp;<button type="submit" style="background: url(icons/thumb-down.png)" title="Down!" name="vote" value="down" /> 
    {% else %} 
    &nbsp;<button type="submit" style="background: url(icons/thumb-down_gray.png)" title="Down!" name="vote" value="down" /> 
    {% endif %} 
    <input name= "content_key" type="hidden" value="{{ c.key.urlsafe() }}"> 
</form> 
+0

ありがとう!それは動作しますが、ページ上のアイコンがひどく壊れてしまいました。私はCSSでサイズを変更しようとしましたが、動作しませんでした。 ボタンではなく画像で動作させる方法はありませんか? –

0

[OK]を私はそれがコードだ、私はこれをしたいかもしれません誰のために私の解決策を掲載しています、私はそれを働いたと思います私は基本的に最初の部分がupvoteを管理し、2番目の部分がdownvoteを管理するコードを2倍にしました。アイコンをクリックすると、投票値が非表示として返されます。 私はコードを二重にすることは避けられないと思います。そうでなければ、押されたアイコンに従って隠し値の値を設定することはできません。

関連する問題