NeoVe
NeoVe

Reputation: 3907

Hide form on submit - Django 1.6

I have this form on my Django 1.6 project:

<form action="/proyecto/" method="POST" id="myform">
                {% csrf_token %}
                <table>
                    <span class="Separador_Modulo"></span>
                        <span class="Sub-Titulo-Aplicacion">SiatPre</span>  
                  <tr>
                    <td >Usuario: {{user}}</td>
                  </tr>
                  <tr><td>
                    <span class="Sub-Titulo-Aplicacion">Tipo de Proyecto: </span>
                    <input class="check-style" type="checkbox" name="curva" value="checkbox" >Petroleo</input>
                  </td></tr>
                  <tr><td>
                    <input class="check-style" type="checkbox" name="curva" value="checkbox" >Gas</input>
                  </td></tr>
                  <tr><td>
                    <span class="Sub-Titulo-Aplicacion">Proyecto: </span>
                    <input class="check-style" type="checkbox" name="tipo" value="checkbox" >Nuevo</input>
                  </td></tr>
                  <tr><td>
                    <input class="check-style" type="checkbox" name="tipo" value="checkbox" >Existente</input>
                  </td></tr>
                  <tr><td>
                    <div class="Contenedor-Elemento-Formulario">
                                <span class="Sub-Titulo-Formulario"> Nombre Proyecto:</span>
                                <input type="text" class="input-style"  name="nombre_proyecto" style="width:96px;"/>
                            </div>
                   </td> </tr>
                   <td><div >
                                <div class="Principio-Boton"> </div>
                                <input name="Aceptar" class="Boton" type="submit"  value="Aceptar" onclick="myclick()"/>
                                <div class="Final-Boton"></div>
                                <div class="Principio-Boton"> </div>
                                <input name="Cancelar" class="Boton" type="submit"  value="Cancelar" />
                                <div class="Final-Boton"> </div>
                            </div></td>
                  </tr>

                </table>
        <table style="margin-bottom:45px; padding:15px 15px 15px 15px;">
            <div>&nbsp;</div>
            <div>&nbsp;</div>
            <tr>
            <td colspan="4" align="center"> 
            <div class="Principio-Boton"> </div>
            <a href="scppp/datos1.html"><input name="Datos" class="Boton" type="submit" value="Datos"/></a>
            <div class="Final-Boton"></div></td></tr>


            <tr>
            <td colspan="4" align="center"> 
            <div class="Principio-Boton"> </div>
            <a href="scppp/libreriaPrePro1.html"><input name="Procesamiento" class="Boton" type="submit" value="Procesamiento"/></a>
            <div class="Final-Boton"></div></td></tr>

            <tr>
            <td colspan="4" align="center"> 
            <div class="Principio-Boton"> </div>
            <a href="scppp/reporte1.html"><input name="Reporte" class="Boton" type="submit" value="Reporte"/></a>
            <div class="Final-Boton"></div></td></tr>

        </table>
        </form>

This code is on my base.html file, however, this form is obviously inherited on other templates by block content tag.

I need to hide specifically this form from other pages when user clicks <input name="Aceptar" class="Boton" type="submit" value="Aceptar" onclick="myclick()"/> not there is an onclick function I declared earlier on this html, the function being like this:

<script>function myclick() {$('#myform').hide().fadeOut(2000); }

</script>

And on <form action="/proyecto/" method="POST" id="myform"> I reference the function by using an id (id="myform"), however, when I click on Aceptar, it does some hiding for a second or so, then when it loads a new template, by POST request to server, I still see this form there, no matter what.

Is this the correct way to achieve what I'm looking for? Or maybe it has to do with POST requests to server?

Any ideas?

Thanks in advance!

Upvotes: 0

Views: 141

Answers (1)

Geo Jacob
Geo Jacob

Reputation: 6009

You have to pass a variable from views.py a = True when you need to display the form, and do the if condition in template,

{% if a %}
<form action="/proyecto/" method="POST" id="myform">
................
</form>
{% endif %}

Upvotes: 1

Related Questions