HTML Forms with PHP

2

I have this great questionnaire, in a modal that when I click the record button, the button does not redirect to the page I want. The error is not of the page registrar.php because I had put a simple alert in it, and it did not work, besides when I click the button nothing happens. This has worked once, but crashed I do not give a damn because. If someone finds some error thank you, I'm already hours trying to find.

    <!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header" style="background-color:#0066cc; color:#FFF;">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h1 class="modal-title">Registrar Aluno</h1>
            </div>
            <div class="modal-body" style="font-size:20px;">

                <form action="registrar.php" method="POST">

                    <p> <i class="fa fa-credit-card fa-lg" aria-hidden="true"></i>
                        <input type="text" tabindex="1" name="n_processo" required placeholder="Nº Processo" maxlength="5" id="n_processo" style="font-size:18px; width:150px; border:1px solid #cccccc; padding-left:5px; border-radius: 5px;"> </p>

                        <br>

                        <p> <i class="fa fa-user fa-lg" aria-hidden="true"></i> 
                            <input type="text" placeholder="Nome" onkeypress="return letras()" tabindex="2" name="nome" id="nome" required maxlength="150" style="font-size:18px; width:400px;border:1px solid #cccccc; padding-left:5px; border-radius: 5px;"> </p>

                            <br>

                            <p> <i class="fa fa-calendar fa-lg" aria-hidden="true"></i>

                                <select tabindex="3" name="dia" required>
                                    <option disabled selected hidden value="">Dia</option>
                                    <? 
                                    for($dia = 1; $dia <= 31; $dia++)
                                    {
                                        if($dia < 10) {
                                            echo "<option>0$dia</option>";
                                        }else
                                        {
                                            echo "<option>$dia</option>";
                                        }

                                    }

                                    ?>
                                </select>


                                <select tabindex="4" name="mes" required>
                                    <option disabled selected hidden value="">Mês</option>
                                    <? 
                                    for($mes = 1; $mes <= 12; $mes++)
                                    {
                                        if($mes < 10)
                                        {
                                            echo "<option>0$mes</option>";
                                        }
                                        else
                                        {
                                            echo "<option>$mes</option>";
                                        }

                                    }

                                    ?>
                                </select>

                                <select tabindex="5" name="ano" required>
                                    <option disabled selected hidden value="">Ano</option>
                                    <? 
                                    $hoje = date("Y");
                                    for($ano = ($hoje-30); $ano <= ($hoje-14); $ano++)
                                    {
                                        echo "<option>$ano</option>";
                                    }

                                    ?>
                                </select><br>

                                <font style="font-size: 15px;color:gray;font-style: italic;">Data de Nascimento</font>

                            </p>



                            <br>

                            <p> <i class="fa fa-university fa-lg" aria-hidden="true"></i>

                                <input type="text" tabindex="6" name="cc" id="cc" required maxlength="9" style="font-size:18px; width:100px; border:1px solid #cccccc; padding-left:5px; border-radius: 5px;text-align: center;"> 
                                -
                                <input type="text" tabindex="7" name="zz" id="zz" required maxlength="4" style="font-size:18px; width:70px; border:1px solid #cccccc; padding-left:5px; border-radius: 5px; text-transform: uppercase;text-align: center;"> 

                                <br>

                                <font style="font-size: 15px;color:gray;font-style: italic;">Cartão de Cidadão</font>

                            </p>

                            <br>
                            <!-- <p style="background-color: rgba(240, 11, 18, 0.8); border-radius: 5px; padding-left: 10px; padding-top: 5px;padding-bottom: 5px; font-size: 15px;">Cuidado! Os próximos campos, depois de criados não podem ser editados!</p> -->

                            <!--  -----------------------------CURSO------------------------------------------------- -->

                            <p><i class="fa fa-question-circle fa-lg" aria-hidden="true"></i>

                                <select tabindex="8" name="escolhe" id="tipo_curso" onchange="mostrar()" required="">
                                    <option disabled selected hidden value="">Tipo do Curso</option>
                                    <option>Profissional</option>
                                    <option>Vocacional</option>
                                </select>

                            </p>
                            <br>

                            <!-- -----------------------------------DIV 1 ------------------------------------- -->

                            <div style="display: none;" id="curso_um">


                                <p> <i class="fa fa-graduation-cap fa-lg" aria-hidden="true"></i>


                                    <select name='cursos1' required tabindex="9">

                                        <option disabled selected hidden value="">Curso</option>

                                        <? 


                                        $sql = "SELECT designacao FROM cursos WHERE id_tipo_curso = 1";

                                        $resposta = mysql_query($sql,$conexao);

                                        while ($row = mysql_fetch_array($resposta)) 
                                        {
                                            $sql = "SELECT designacao FROM cursos WHERE ";

                                            echo "<option value='" . $row['designacao'] ."'> ".$row['designacao']."</option>";

                                        }


                                        ?>
                                    </select>
                                </p>

                                <br>

                                <P><i class="fa fa-clock-o fa-lg" aria-hidden="true"></i>

                                    <input type="text"  name="ciclo" id="ciclo" tabindex="10" maxlength="4" placeholder="2010" style="border:1px solid #cccccc; font-size:18px; letter-spacing: 2px; width:100px;border-radius: 5px; text-align: center;" onkeyup="tenta()" required>

                                    -
                                    <input type="text" name="ciclo2" id="lol" tabindex="11" placeholder="2013" readonly style="border:1px solid #cccccc; font-size:18px; letter-spacing: 2px; width:100px;border-radius: 5px; text-align: center;">

                                    <br>

                                    <font style="font-size: 15px;color:gray;font-style: italic;">Ciclo de Formação</font>
                                </P>

                            </div>

                            <!-- -----------------------------------DIV 2 ------------------------------------- -->

                            <div style="display: none;" id="curso_dois">

                                <p>  <i class="fa fa-graduation-cap fa-lg" aria-hidden="true"></i>
                                    <select name='cursos2' required tabindex="9">
                                        <? 


                                        $sql = "SELECT designacao FROM cursos WHERE id_tipo_curso = 2";

                                        $resposta = mysql_query($sql,$conexao);

                                        while ($row = mysql_fetch_array($resposta)) 
                                        {
                                            $sql = "SELECT designacao FROM cursos WHERE ";

                                            echo "<option value='" . $row['designacao'] ."'> ".$row['designacao']."</option>";

                                        }


                                        ?>
                                    </select>
                                </p>

                                <br>

                                <P><i class="fa fa-clock-o fa-lg" aria-hidden="true"></i>

                                    <input type="text" name="ciclo3" id="ciclo3" tabindex="10" maxlength="4" placeholder="2010" style="border:1px solid #cccccc; font-size:18px; letter-spacing: 2px; width:100px;border-radius: 5px; text-align: center;" onkeyup="numeros2()" required>

                                    -
                                    <input type="text" name="ciclo4" id="ciclo4" tabindex="11" placeholder="2012" readonly  style="border:1px solid #cccccc; font-size:18px; letter-spacing: 2px; width:100px;border-radius: 5px; text-align: center;">
                                    <br>

                                    <font style="font-size: 15px;color:gray;font-style: italic;">Cartão de Cidadão</font>
                                </P>

                            </div>



                            <div class="modal-footer">
                                <button type="submit" class="btn btn-primary"><i class="fa fa-floppy-o fa-2x"></i></button>
                                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times fa-2x"></i></button>

                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    
asked by anonymous 06.05.2016 / 03:21

2 answers

1

The problem was that fields were required . because when submitting the form, the div that was hidden, had value null and therefore did not let submit. So I did like this:

$(".escolher_curso").change(function (){
                            var x = document.getElementById('tipo_curso').selectedIndex;
                            if(x==1)
                            {
                                $(".mudarcurso1").show();
                                $(".mudarcurso2").hide();

                                document.getElementById("cursos1").required = true;
                                document.getElementById("ciclo").required = true;
                                document.getElementById("lol").required = true;

                                document.getElementById("cursos2").required = false;
                                document.getElementById("ciclo3").required = false;
                                document.getElementById("ciclo4").required = false;

                            }
                            else if (x==2)
                            {
                                $(".mudarcurso1").hide();
                                $(".mudarcurso2").show();

                                document.getElementById("cursos1").required = false;
                                document.getElementById("ciclo").required = false;
                                document.getElementById("lol").required = false;

                                document.getElementById("cursos2").required = true;
                                document.getElementById("ciclo3").required = true;
                                document.getElementById("ciclo4").required = true;
                            }


                        });
    
08.05.2016 / 18:17
0

Note that, as it is, your button footer has no logic whatsoever. I would venture to say that he does nothing.

If you want the button to make a post , you have two options:

  • Use the <input> tag instead of the button (traditional way). Do not forget that the type has to be "submit" ( <input type="submit"> );
  • Add javascript to your <button> to do the post. This allows you to have a more ornate button, but requires more code.

I hope I have helped:)

    
06.05.2016 / 14:10