input declared not accessible in javascrit and php

Asked

Viewed 41 times

1

I created a form and I’m trying to get the data of a radio button, and an input, but I’m not able to access them via POST in php or the javascript in which I’m using a function to disable the 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'];

php’s return message is as follows: Undefined index in Cd_sex

  • You only posted part of the code. Where is the rest of the code referring to name, surname etc...?

  • updated friend

  • They are not posted because they are disabled. And its js code to take the disableds tries to reference the inputs by an id that does not match what is in html

  • Get it wrong, man

2 answers

2


Some errors in your code:

  1. <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"
    
  2. <input required name="Cd_sexo" missed id="Cd_sexo" but as has male and female put id="Cd_sexoM" and id="Cd_sexoF" respectively and in the script

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

  4. If you choose to $_POST then the form tag should be method="post"

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

When to use GET function and when to use POST function


there is something that does not invalidate your code but in the future may cause some inconvenience:

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

and

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

the two values of for are equal, hit this!

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

0

You’re a little confused there but let’s go.

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

In your function click edit has 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 variable $_POST if they have arrows, otherwise there are not so check before so:

$sexo = isset( $_POST['Cd_sexo'] )? $_POST['Cd_sexo'] : '';

Browser other questions tagged

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