Change the value of input type text in php

5

I have a value assigned to a variable in php and I show it in a type text. I wish that by clicking on a checkbox I can edit and change that value.

1.- If I click and change the value, when submitting with submit, it shows me the change made.

2.- If I do not want to change the value, it simply tells me that the variable does not exist.

<html lang="es">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1 user-scalable=no">
        <title>FORMULARIO</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        </head>
            <?php
                $nombre_completo="Pablo";
                $jefe_inmediato="[email protected]";
            ?>
            <body>
                <div class="form-bottom">
                    <form role="form" class="login-form" action="verificar.php" method="POST" id="login-form">
                        <div class="form-group hidden">
                            <div class="alert alert-warning fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <i class="glyphicon glyphicon-warning-sign alert-icon "></i>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="nombre_solicitante"class="col-xs-12 col-sm-6 col-md-2 col-form-label">Nombre del Solicitante  </label>
                            <div class="col-md-4"><input type="text" id="nombre_solicitante" name="nombre_completo" placeholder="<?php echo $nombre_completo; ?>" class="form-control" disabled></div>
                            <label for="jefe_inmediato"class="col-xs-12 col-sm-6 col-md-2 col-form-label">Jefe Inmediato </label>
                            <div class="col-md-4"><input type="text" id="jefe_inmediato" name="jefe_inmediato" value="<?php echo $jefe_inmediato; ?>" class ="form-control" disabled></div>
                        </div>
                        <div class="form-group row">
                            <div class="col-md-6"><input class="form-check-input" id="chk" type="checkbox" name="chk" value="" />Activa la casilla si el correo de jefe inmediato es incorrecto es incorrecto y escribelo</label></div>
                            <script type="">
                            document.getElementById('chk').onchange = function() {
                                document.getElementById('jefe_inmediato').disabled = !this.checked;
                                $("#jefe_inmediato").focus().select();
                            };
                            </script>
                        </div>
                    </div>
                    <button type="submit" class="btn" id="btn-formulario" name="enviar" value="enviar" >Aceptar</button>                    
                </form>
                <button type="submit" class="btn" id="btn-cancelar" name="cancelar" value="cancelar" >Cancelar</button>
                <script type="text/javascript">
                document.getElementById("btn-cancelar").onclick = function () {
                    location.href = "index.php";
                };
                </script>
    </body>
</html>

    <html lang="es">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1 user-scalable=no">
        <title>VERIFICAR LOS DATOS</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
                <div class="row">
                    <div class="col-lg-offset-1 col-xs-12 col-lg-10 form-box"><!--Ancho de la pagina -->
                        <div class="form-bottom">
                            <form role="form" class="login-form" method="POST" id="login-form" action="enviar.php">
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover table-condensed">
                                        <tfoot>
                                            <tr>
                                                <td colspan="5" class="text-center">¿No son correctos los datos? <a href="index.php" target=""><p class="text-danger"> Cancela e ingresa de nuevo los datos</p></a></td>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div>
                                <div class="text-center">
                                    <button type="submit" class="btn btn-primary">Enviar Solicitud a </button> <?php echo '<h4>' .$_POST['jefe_inmediato'].'</h4>';?>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
    </body>
</html>

[![No me muestra la iformacion si no la deseo cambiar][3]][3]
    
asked by Juan Pablo Bustamante Luna 26.10.2016 в 16:28
source

1 answer

0

Instead of putting disabled put readonly in input . When you use disabled the values are not going to be sent to the php but with readonly if.

    
answered by 26.10.2016 / 16:32
source