input declare is not accessible in javascrit and php

2

I created a form and I'm trying to get the data from a radio button, and an input, but I'm not able to access them via POST in php or javascript in which I'm using a function to disable fields

Html

<form name="cdUsuario" class="cadastroUsuario" type="submit">
              <div class="row">
                <div class="input-field col s12 l6">
                    <i class="mdi-action-account-circle prefix"></i> 
                  <input id="nome" name="nome" value="<?php echo $result['nm_nome'] ?>" type="text" disabled>

                  <label for="nome">Primeiro Nome</label>
                </div>
                <div class="input-field col s12 l6">
                  <input id="sobrenome" required name="sobrenome" value="<?php echo $result['nm_sobrenome'] ?>" type="text"  disabled="disabled">
                  <label for="sobrenome">Sobrenome</label>
                </div>
              </div>
              <div class="row">

                <div class="input-field col s12 l6">
                <i class="mdi-communication-email prefix"></i>
                  <input id="email"  required name="email_altera" type="email" class="validate" value="<?php echo $result['nm_email'] ?>" disabled="disabled">
                  <label for="icon_email" data-error="Incorreto" data-success="Válido">E-mail</label>
                </div>
                <div class="input-field col s12 l6">
                  <p>

                    <input required name="Cd_sexo" value="Masculino" type="radio" id="rd_masculino" <?php echo $Result_sexoM ?> disabled="disabled"/>
                    <label for="rd_masculino">Masculino</label>
                    <input required name="Cd_sexo" type="radio" value="Feminino" id="rd_feminino" <?php echo $Result_sexoF ?> disabled="disabled"/>
                    <label for="rd_feminino">Feminino</label>
                  </p>
                </div>
              </div>

              <div class="row">
                <div class="input-field col s12 l6">
                <!-- Máximo de 11 caracteres, o suficiente para um número padrão DDD + número, exemplo: 13991636095 -->
                 <i class="mdi-communication-call prefix"></i> 
                  <input id="telefone"  name="telefone" type="text" value="<?php echo $result['cd_telefone_fixo'] ?>" maxlength="11" disabled="disabled"> <!-- minlength="11" -->

                  <label for="telefone">Telefone</label>
                </div>

                <div class="input-field col s12 l6">
                  <i class="mdi-hardware-phone-iphone prefix"></i>
                  <input id="celular" required name="celular" type="text" value="<?php echo $result['cd_telefone_movel'] ?>" maxlength="11"disabled="disabled">
                  <label for="senha">Telefone Celular</label>

                </div>


                 <div class="input-field col s12 l6">
                  <i class="mdi-action-https prefix"></i>
                  <input id="senha" required name="senhaEdita" type="password" value="<?php echo $result['cd_senha'] ?>" class="validate" disabled="disabled">
                  <label for="senha">Senha de Acesso</label>

                </div>

                <div class="input-field col s12 16">
                        <input type="checkbox" id="perfilprofissional" name="boxProfissional"
                         onclick="Mudarestado('formProfissional')">
                        <label for="perfilprofissional">Perfil Profissional</label>

                        </div>




                    <div class="row" id ="formProfissional" name="fmProfi" style="display: none;">
                         <div class="input-field col s12 l6">                           

               <select class = "browser-default">
                    <option value = ""  disabled selected>Área de Atuação</option>
                  <option value = "1">Informática</option>
                  <option value = "2">Aparelhos Eletrônicos e Eletrodomésticos</option>            
                  <option value = "3">Aulas</option>
                  <option value = "4">Autos</option>
                  <option value = "5">Consultoria</option>
                  <option value = "6">Eventos</option>
                  <option value = "7">Moda e Beleza</option>
                  <option value = "8">Reformas e Serviços Gerais</option>
                  <option value = "9">Saúde</option>
                  <option value = "10">Serviços Domésticos</option>
                  <option value = "11">Comércio</option>
                  <option value = "12">Esportes e Lazer</option>
               </select>
            </div>

                <div class="input-field col s12 l6">
                <i class="mdi-action-wallet-travel prefix"></i>
                  <input id="email" type="email"  name="Ped_email">
                  <label for="icon_email" data-error="Incorreto" data-success="Válido">Formação</label>
                </div>


                     <!-- TextArea Observações do meu perfil profissional --> 
               <div class="row">
          <div class="input-field col s12 16">
            <textarea id="textarea2" class="materialize-textarea" data-length="120"></textarea>
            <label for="textarea2">Observações</label>
          </div>
        </div>
    </div>  

                <!-- <a href="javascript:void(0);">Meus anúncios</a></label>

                <a href="javascript:void(0);">Meus pedidos</a></label> -->
              </div>


                    <button  type="submit" class="btn blue center-align"  name="Salvar" id="SalvarDados" >Salvar

                    </button>

                    <button class="btn blue center-align"  name="Editar" id="EditarDados">Editar Dados

                    </button>


                    <!-- Loader AJAX --> 
                    <font color="red"<p><center><h7 class="emailCadastrado"></h7></center></p></font>
                <font color="green"<p><center><h7 class="sucessoCadastro"></h7></center></p></font>



          </div>
        </div>
    </div>



        </form>

javascript

<script>
$(document).ready(function() {
  $("#EditarDados").click(function (event) {
    event.preventDefault();
    $("#nome").prop("disabled", false);
    $("#sobrenome").prop("disabled", false);
    $("#email").prop("disabled", false);
    $("#Cd_sexo").prop("disabled", false);
    $("#telefone").prop("disabled", false);
    $("#celular").prop("disabled", false);
    $("#senhaEdita").prop("disabled", false);
  });


});
</script>

php

include_once("usuario_class.php");
$nome=$_POST['nome'];
$sobrenome=$_POST['sobrenome'];
$telefone_fixo=$_POST['telefone'];
$telefone_movel=$_POST['celular'];
$email=$_POST['email_altera'];
$sexo=$_POST['Cd_sexo'];
$senha=$_POST['senha'];

The return message from php is as follows: Undefined index in Cd_sex

    
asked by anonymous 15.06.2018 / 03:17

2 answers

2

Some errors in your code:

  • <input id="senha" required name="senhaEdita"... correct is with id senhaEdita to be consistent with $ ("#senhaEdita").prop("disabled", false);

     <input id="senhaEdita" required name="senhaEdita"
    
  • <input required name="Cd_sexo" was missing id="Cd_sexo" but since it has both male and female id="Cd_sexoM" and id="Cd_sexoF" respectively and in script

            $("#Cd_sexoM").prop("disabled", false);
            $("#Cd_sexoF").prop("disabled", false);
    
  • So your form tag is via GET , so in PHP it has to be $_GET and not $_POST

  • If you opt for $_POST then the form tag must be method="post"

    <form name="cdUsuario" class="cadastroUsuario" action="" method="post">
    
  • #

    When should I use GET function and when should I use POST function

      

    There is something that does not invalidate your code but in the future it may cause some disruption:

    <label for="senha">Telefone Celular</label>
    

    and

    <label for="senha">Senha de Acesso</label>
    

    The two values of for are equal, set it right!

      

    An example of a disorder could be .find( "label[for='senha'...

        
    15.06.2018 / 03:59
    0

    It's a bit confusing, but let's go.

    In your form tag you need to include <form method="POST">...</form>

    In your edit click function you have to take

    $("#Cd_sexo").prop("disabled", false);
    

    and include

    $("#rd_masculino").prop("disabled", false);
    $("#rd_feminino").prop("disabled", false);
    

    And do not forget that radios and checkboxes only exist in the $ _POST variable if they have been set, otherwise they do not exist then check before:

    $sexo = isset( $_POST['Cd_sexo'] )? $_POST['Cd_sexo'] : '';
    
        
    15.06.2018 / 03:57