HTML Forms with PHP

Asked

Viewed 102 times

3

I have this great quiz, inside 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 didn’t work, besides when I click the button nothing happens. This worked once, but it stopped working for no reason. If anyone finds any mistakes I appreciate it, I’m already hours away 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>
  • What is the severity of the ? , E_ERROR, E_NOTICE or E_WARNING error

  • What do you mean @Edx ? I’ve never used this kind of error_reporting. But the error is only that when you click on the Submit button, nothing happens.

  • I believe that the answer below Renan is what you need, I think he killed 'Charada', if you want to delve into "error_reporting" look at the PHP Link the right way http://br.phptherightway.com/#erros_e_exceptions, I hope I helped

2 answers

2


The problem was that the camps were required. because when submitting the form, the div that was hidden, had value null and that’s why I wouldn’t let you submit. So I did so:

$(".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;
                            }


                        });

0

Notice that, the way it is, its button the footer has no logic. I venture to say that for this reason it does nothing.

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

  • Tag <input> instead of button (traditional form). Do not forget that the type has to be "Submit" (<input type="submit">);
  • Add javascript to your <button> for him to perform the post. This allows you to have a more embellished button, but requires more code.

I hope I’ve helped :)

  • I tried the input and put javascript in the button but none of it worked.

  • The problem is really because when you get to the field of choosing the course, javascript will have to choose between 2 div’s and because of that I think it doesn’t work. Any suggestions?

  • A tag input like submit will always post the page to the address defined in the attribute action the form you belong to. Maybe you’re not handling the server-side post. I suggest debugging the PHP code, because the change to Submit is enough to trigger the post.

  • In php, the form only has an echo to test. the problem and even the scripts involved in the form as I took them, tested and worked well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.