If inside a php <form>

Asked

Viewed 167 times

0

Good morning guys, I need to do one IF for a conditional in the code below, but I’m encountering some difficulties, the IF is not running.

I need the profile of "AINEC Coordinators" is redirected to another page (.php coordinators) and not the one on <form class="contact-form" method="POST" action="envia.php">.

                <form class="contact-form" method="POST" action="envia.php">
                    <input type="text" class="input" placeholder="Nome" name="nome" required="">
                    <input type="email" class="input" placeholder="E-mail" name="email" required="">
                    <input type="text" class="input" placeholder="Telefone" name="telefone" required="">
                    <input type="text" class="input" placeholder="Documento de Identificação (CPF, Passaporte)" name="documento" required="">
                    <div>
                        <label>País de origem: </label>
                    <select name="nacionalidade" id="paises">
                            <option value="Brasil" selected="selected">Brasil</option>
                            <option value="Afeganistão">Afeganistão</option>
                            <option value="África do Sul">África do Sul</option>
                            <option value="Albânia">Albânia</option>
                            <option value="Alemanha">Alemanha</option>
                            <option value="Andorra">Andorra</option>
                            <option value="Angola">Angola</option>
                            <option value="Anguilla">Anguilla</option>
                            <option value="Antilhas Holandesas">Antilhas Holandesas</option>
                            <option value="Antárctida">Antárctida</option>
                            <option value="Antígua e Barbuda">Antígua e Barbuda</option>
                            <option value="Argentina">Argentina</option>
                            <option value="Argélia">Argélia</option>
                            <option value="Armênia">Armênia</option>
                            <option value="Aruba">Aruba</option>
.............
                    <br>
                    <div>

                        <label>Perfil:  </label>
                    <select name="perfil" required="" >

                          <option value="Alunos da rede Adventista de São Paulo">Alunos da rede Adventista de São Paulo(UNASP)</option> <!-- 120 reais -->
                          <option value="Alunos e Professores">Alunos e Professores - Instituições Adventistas</option> <!-- 120 reais -->
                          <option value="Profissionais da Saude">Profissionais da Saude</option> <!-- 200 reais -->
                          <option value="Coordenadores AINEC" selected="selected">Coordenadores AINEC-LA</option> <!-- 500 reais -->


                    </select>
                   </div>

                   <br>


                     <div class="aviso" >
                        <label><strong><font color="#FF0000">IMPORTANTE !!!</font></strong></label><br>
                        <li><label> As inscrições só serão concluídas após o Pagamento.</label><br></li>
                        <li><label> Não esqueça de verificar se o seu perfil está correto.</label></li>



                    </div>

                   <br>

                    <button class="main-btn">Finalizar Inscrição</button> 
                </form>
  • Where is the if?

  • It is in <div class="col-Md-8 col-Md-offset-2"> <form class="contact-form" method="POST" action="send.php"> <? php if ($profile == "AINEC Coordinators"): ? > <form class="contact-form" method="POST" action="coordinators.php"> <? php endif ? > <input type="text" class="input" placeholder="Name" name="name" required="">

1 answer

0


Like the Select and the Form do not have id eu assigns, profile and Form1, respectively.

As the send button is not a submit, from what I understand is just make a ifchanging the action of formbased on the chosen profile:

<script type="text/javascript">

$("#perfil").on('change', function(){
    if ($("#perfil").val() == "Coordenadores AINEC") {
        $('#form1').attr('action','coordenadores.php');
        $('#form1').submit();
    }else{
        $('#form1').attr('action','envia.php');
        $('#form1').submit();
    }
})
 </script>

Edit - 1: I forgot to tell you I’m using jquery.

  • I think it was missing you include the 'onChange' event from select to fire the code you wrote.

  • 1

    One is missing even an event! Thanks @Leandrocastro, I will fix.

  • 1

    could also have used $("#profile"). change(Function.... direct to . on(), anyway is right.

  • worked out!! thanks for the personal help.

Browser other questions tagged

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